0

This is my code :

print_r($args)

//Output 
array(6) { ["post_type"] => string(9) "order" 
           ["date_query"] => array(2) { 
               ["before"] => string(3) "now" 
               ["compare"] => string(1) "=" 
           } 
           ["post_status"] => string(9) "validated" 
           ["posts_per_page"] => int(-1) 
           ["orderby"] => string(5) "title"
           ["order"] => string(3) "ASC" 
         } 

And this is the request :

$wp_query = new \WP_Query( $args );
var_dump( $wp_query->request );
  
//Output 
"SELECT wp_posts.* 
 FROM wp_posts 
 WHERE 1=1 
 AND ( wp_posts.post_date < '2020-08-07 16:46:27' ) 
 AND wp_posts.post_name = 'asc'
 AND wp_posts.post_type = 'order'
 AND ((wp_posts.post_status = 'validated'))
 ORDER BY wp_posts.post_title ASC "

So WP_Query in the query says wp_posts.post_name = 'asc' !!!

Why ?

0

The reason is :

My custom post type is "order"

So $args['post_type'] = "order"

And $args['order'] = "asc"

And for some reason WP_Query made wp_posts.post_name = 'asc'

I fixed this adding a prefix for my custom post type name like foo-order so $args['post_type'] = "foo-order"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.