WP_Query args category_name issue
-
Hello,
I have my own theme run on WordPress 6.1.1. and I think just after update to 6.1.1. (however I am not sure), I’ve noticed strange error.
I have piece of code that gets posts from the category slug “blog-en” plus some more arguments for the WP_Query – here is the code:
$args = array( 'category_name' => 'blog-en', 'post_type' => 'post', #'category__in' => 3, 'order' => 'DESC', 'orderby' => 'date', 'posts_per_page' => '4', ); do_action('qm/info', $args); #wp_reset_postdata(); $htPosts = new WP_Query; $htPosts->query($args); do_action('qm/debug', $htPosts->request); do_action('qm/debug', $htPosts);
As you can see I am checking the SQL request in the Query Monitor and it gives me the SQL:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (369) AND 0 = 1 ) AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private'))) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 4
In bold you can see 0 = 1 in the query, and this is wired to me since if I change the php code and choose the category__in => 3 (this is the ID of category_name = blog-en), the query looks like:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_term_relationships AS tt1 ON (wp_posts.ID = tt1.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (369) AND tt1.term_taxonomy_id IN (3) ) AND ((wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private'))) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 4
where there is no magical 0 = 1 and I’ve got proper results on my page.
What is wrong with my code? Maybe this is some issue with WordPress 6.1.1?
Could somebody helps me?
Best regards,
ZiemoT
- The topic ‘WP_Query args category_name issue’ is closed to new replies.