0

I've googled and tried to figure this out on my own but here goes. I'm querying a custom post type and certain posts within that custom post type with an ID of 180. I then need to order these posts by a custom field. This is my code:

$namskeid = new WP_query(array(
                            
                            'posts_per_page' => '6',
                            'post_type' => 'namskeid',
                            'meta_query' => array(
                                array (
                                'key' => 'course_type_display',
                                'compare' => 'LIKE', 
                                'value' => get_the_ID( 180 )
                            ))
                        ));
                         

Is there any way to do this?

1 Answer 1

0

I finally figured it out. I failed to specify meta_type = Date and orderby => 'meta_value_num'.

Here is the code that works:

 $namskeid = new WP_query(array(
                        
                        'posts_per_page' => '6',
                        'post_type' => 'namskeid',
                        'meta_type' => DATE,
                        'orderby'   => 'meta_value_num',
                        'order' => 'ASC',
                        'meta_key'  => 'course_date',
                
                        'meta_query' => array(
                            
                            array (
                            
                            'key' => 'course_type_display',
                            'compare' => 'LIKE', 
                            'value' => get_the_ID( 180 )
                        ))
                        
                     
                    ));
                    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.