Limit taxonomy results to a single cpt

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')) {
        set_query_var('post_type','report');
    }
}
add_action( 'pre_get_posts', 'my_restrict_to_report' );

Not tested

Leave a Comment