WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two cpt's, events and reports, they both share the taxonomy locations, I have my taxonomy-locations.php, but that is showing reports & events for location, I just want to show reports for location. Can someone help me out with how this query should go?


share|improve this question
up vote 1 down vote accepted

Before the loop in your taxonomy-locations.php file,

global $wp_query;
$args = array_merge( $wp_query->query, array( 'post_type' => 'report' ) );
query_posts( $args );

You could, alternatively, modify the query using an appropriate hook (this would be the most effecient method) - but since it is run for most queries, you would need to check it's actually a query for which you want to set post type to 'report'. For example:

function my_restrict_to_report() {
    //And any other checks
    if (!is_admin() && is_tax('location')) {
add_action( 'pre_get_posts', 'my_restrict_to_report' );

Not tested

share|improve this answer
Thanks Stephen, perfect timing as I was just asked to show the site in its current status. – Chuck Feb 24 '12 at 17:56
nice job remembering the is_admin() check – helgatheviking Feb 24 '12 at 18:01
@helgatheviking I'm not sure it's necessary - I think is_tax covers it, but better safe than sorry I suppose... – Stephen Harris Feb 24 '12 at 18:05

i believe you can also do this via the pre_get_posts action. the $query variable is the entire query object and it is passed 'by reference' meaning that anything you do to it inside the function will modify the original query

add_action('pre_get_posts', 'kia_limit_tax' );

function kia_limit_tax( $query ) {
    //check that we're in the locations taxonomy before modifying the query
            //which is the more elegant way to write this:

is_taxonomy() is deprecated and is_tax() should be used http://codex.wordpress.org/Function_Reference/is_tax

share|improve this answer
Good point about the set_query_var. is_taxonomy is depreciated though, and returns true if 'locations' exists as a taxonomy, not if the locations archive page is being displayed. – Stephen Harris Feb 24 '12 at 17:26
really? that's a bummer. how are you supposed to do it now then? there is clearly a difference between whether a tax exists and whether you are on that tax's archive.. to taxonomy_exists() doesn't seem right – helgatheviking Feb 24 '12 at 17:47
is_tax checks if its the taxonomy's archive page. – Stephen Harris Feb 24 '12 at 17:52
yup, just found that myself. will correct. – helgatheviking Feb 24 '12 at 17:53

Your Answer


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.