I have 2 custom post types that use some of the same taxonomies. I would like to be able to show all entries in the taxonomy ( no problem here) and then just each of the post types. But I would like to do it without creating a mess of custom pages using a template.

Can I set up a function to change the post_type query_var when the link is clicked? SO if I had a set of navigation links in my left sidebar, the set to 'designer' post type would set the post_type query_var to 'designer'. The same would need to happen for the 'boutique' post type navigation links.

I think I may need to use some javascript but am unsure. Is this possible? I'm not an expert by an means but I believe this MIGHT be possible,

Thanx in advance!

1 Answer 1


You can use pre_get_posts filter hook to set the post type passed by the user:

paste this code in your theme's functions.php file:

function user_set_type( $query ) {
    //only on your taxonomy page
    if ( $query->is_tax('YOUR_CUSTOM_TAXONOMY') ) {

        //and only if the guesst has selected a type
        if (isset($_GET['UTYPE']) && !empty($_GET['UTYPE'])){
            $query->set( 'post_type', $_GET['UTYPE'] );
    return $query;
add_filter( 'pre_get_posts', 'user_set_type' );

Change YOUR_CUSTOM_TAXONOMY to the name of your taxonomy, then on your taxonomy page or widgets all you need to do is create links with the post_type as parameters in them eg:

<a href="<?php echo get_permalink() . '?UTYPE=designer"; ?>">Designers</a> - <a href="<?php echo get_permalink() . '?UTYPE=boutique" ?>">Boutiques</a>
  • Thanx! That worked perfectly, wasn't aware of pre_get_posts method.
    – dkmojo
    Jun 9, 2011 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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