Include custom post type in “all posts”

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

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

Read More
  • 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?

Related posts

1 comment

  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 .

Comments are closed.