1

(Working of off an existing team that the client already purchase.)

I have a WordPress install with a couple of custom post types:

  • portfolio
  • testimonials

I've set the taxonomy to hierarchical' => false,, the tagging options are available in the backend and I can display them on the front-end.

However, when I click one of the tags, I go to the list of standard posts with that tag, not to the list of custom posts (portfolio or testimonials) with that tag.

Is it possible to display both regular and custom posts in the same taxonomy?

1 Answer 1

1

Filter pre_get_posts:

add_filter( 'pre_get_posts', 'wpse_98213_add_post_types_to_tax_query' );

/**
 * Let WP search for custom post types on taxonomy archives.
 *
 * @wp-hook pre_get_posts
 * @param   object $query
 * @return  object
 */
function wpse_98213_add_post_types_to_tax_query( $query )
{
    if ( ! is_main_query() or ! is_tax( 'your_taxonomy_name' ) )
        return $query;

    $query->set( 'post_type', array ( 'portfolio', 'post' ) );

    return $query;
}

More examples in our tag .

2
  • Stupid question, but where should I add this? In the template being used (Archive?), in function.php, ... May 5, 2013 at 17:49
  • functions.php or a plugin. See also: Where do I put the code snippets?
    – fuxia
    May 5, 2013 at 17:50

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.