quey posts from different categories with taxonomy

I wonder if someone could help me.

I just upgrade my wordpress and start to use taxonomy.

Read More

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

www.website.com/ad-category/cars

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!!

Related posts

Leave a Reply

2 comments

  1. 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(
        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
        ),
        array(
            '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!

  2. 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
    </div>
    <?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?