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 ?
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 ?
Share Improve this question edited Aug 7, 2020 at 15:13 mozboz 2,6281 gold badge12 silver badges23 bronze badges asked Aug 7, 2020 at 14:54 J.BizMaiJ.BizMai 9002 gold badges10 silver badges30 bronze badges1 Answer
Reset to default 0The 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"