I wonder if someone could help me.

I just upgrade my wordpress and start to use taxonomy.

what I want to do is to query posts from different categories.

I used to do it like this query_posts('cat=5');

but with taxonomy added to my categories, doesnt work anymore for example if I go to a category page the link goes like this


I guess my taxonomy category name is "ad-category" and the category name is cars

but how could I query posts from categories ids, example 5,6,7,8 etc..

Thak you for your time!!

  • Since I don't have time to give a real answer at the moment, I'll leave a comment with the quick answer: use WordPress 3.1-beta. It can do what you're trying to do (ad-category=1,2,3,4 as a query var). Commented Dec 13, 2010 at 20:37

2 Answers 2


As Bloch commented, 3.1 provides a way to easily accomplish this. Here's a terrific article describing exactly how to execute advanced taxonomy queries. Here's the plugin to run the 3.1 beta.

Here is some slightly modified code from an example in the advanced taxonomy queries article:

$adcatquery = wp_parse_args( $query_string );

$adcatquery['tax_query'] = array(
        'taxonomy' => 'ad-category', //custom taxonomy name
        'terms' => array( 'cars', 'trucks', 'whatever' ), //custom taxonomy terms
        'field' => 'slug', //refers to $query_string, may use ID
        'operator' => 'IN' //NOT IN excludes terms
        'taxonomy' => 'model', //custom taxonomy name
        'terms' => array( 'corolla', '4runner' ), //custom taxonomy terms
        'field' => 'slug', //refers to $query_string, may use ID
        'operator' => 'IN' //NOT IN excludes terms

query_posts( $adcatquery );

This should give you a decent idea (haven't tested it though)... good luck!


I'm not sure if this is exactly what you're looking for, but it was working for me to grab different post from different taxonomies and doing stuff with them:

<?php $loop = new WP_Query( array( 'post_type' => 'YOUR_POST_TYPE_NAME', 'posts_per_page' => 4 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="some-post-class">
do something here
<?php wp_reset_query(); ?>
<?php rewind_posts(); ?>

Using that I was able use that however many times I needed to run though my custom post types. I ended up going a slightly different route, by adding a foreach loop around the outside and running thru each of my taxonomies to set a variable dynamically. You can see my post at: Dynamic variable for custom taxonomy in loop?

Your Answer

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