Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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

share|improve this question
    
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). –  John P Bloch Dec 13 '10 at 20:37
add comment

2 Answers

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!

share|improve this answer
add comment

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?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.