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.

On a taxonomy archive, how does one create multiple loops for different post types that share that taxonomy? I'm using taxonomy-themes.php so that it applies to all three of the terms in the 'themes' taxonomy (climate change, governance, peace building).

On each term's archive page, I want to output the main taxonomy loop (posts), and then I want to create loops for each of 'events', 'resources' and 'staff' (all of which are custom post types). I'm assuming that I create new wp_query for each of the post types, but how do I tell that query which term I want it to get 'events' from (ie. the current archives' term)?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

As you point out, if you want separate loops for different post types you'll need to use a separate WP_Query() for post type. In the template you can get the current term (ID) being viewed via: get_queried_object_id() (see source)

$args = array( 
          'post_type' => 'staff',
          'tax_query' => array( 
             array(
              'taxonomy' => 'themes',      
              'terms' => get_queried_object_id(),
              'field' => 'id'
             )
          ),
        );
$staff = WP_Query( $args );
share|improve this answer
    
Thanks very much Stephen. That did it perfectly. And wow is queryposts.com helpful. –  Christopher Jun 6 '13 at 11:45

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.