Using category__and with $wp_query->query
-
Hello all.
I am writing a custom template to allow me to filter posts in my own way, based on information passed on the query string. This has all been working fine till i get to the point where i want to only see posts that are in both category X AND category Y.
So.. i start using category__and, but can’t get it to work. If the variable qr_cat is passed in via GET then the page just shows every post in the system not filtered at all. With out the qr_cat variable then all posts are correctly filtered by $blog_category_id var. Now then, I understand that category__and needs to passed an array of category ids to work, but I can’t for the life of me figure out how to do that in this instance.
All the support i can find is for using it with query_posts not $wp-query. Any help anyone can provide is much appreciated. Revelant section of code below:
<?php $my_query = 'showposts=2&paged=' . $paged . 'orderby=date'); if($_GET["qr_a"]) { $my_query .= '&author_name=' . $_GET["qr_a"]; } else if($_GET["qr_m"] == "year") { add_filter('posts_where', 'filter_more_than_one_year'); } else if($_GET["qr_m"]) { $my_query .= '&year=' . substr( $_GET["qr_m"], 2, 4 ) . 'monthnum=' . substr( $_GET["qr_m"], 0, 2 ); } if($_GET["qr_cat"]) { $my_query .= 'category__and=' . $blog_category_id . "," . $_GET["qr_cat"]); } else { $my_query .= 'cat=' . $blog_category_id; } $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query($my_query); ?>
- The topic ‘Using category__and with $wp_query->query’ is closed to new replies.