Written by: Aleš Sýkora

The Author of Toolset.wiki. Big fan of Toolset plugins and WordPress.

I am big fan of WordPress and Toolset plugins. I have done many projects based on WordPress. I also have experience with online marketing, PPC advertising and SEO. I live in Czech Budweis – the town of Budweiser Budvar breverage in the south of the Czech Republic – the heart of Europe.

I love skateboarding, snowboarding, frisbee, fitness, healthy lifestyle, tattoos, mountain biking and other sports. I enjoy having time with friends with good beer and good music.

Restrict post types in taxonomy archive

Last Update: 10. 11. 2019 , Category:

If you need to restrict which custom post types will display in taxonomy archive, you need to do it with some PHP. Here is how to do it.

For example: You are using same taxonomy called “Product category” for 3 Custom Post Types. Two of them are products – Cups, Plates. 3rd one is helper for Call To Actions displayed for each category. So you do not want to display CTA in Product Category Archive. Then you need to use this code snippet and define which CPTs should be displayed.

Create a code snippet at Toolset > Settings > Custom Code.

/**
 * Restrict post types included in taxonomy archive
 */
 
 function ts_modify_tax_archive( $query ){
 
    $tax = 'category-slug'; // Edit taxonomy slug
 
    if ( $query->is_tax( $tax ) && $query->is_main_query() ) {
 
        $query->set( 'post_type', array( 'slug1', 'slug2' ) ); // Edit slugs of post types to include
    }
}
add_action( 'pre_get_posts', 'ts_modify_tax_archive' );

Support Us via our Affiliate link!

Toolset logo WordPress

What to do next?

Need a Toolset License?

Buy via affiliate link!

Looking for a tutorial?


Help other users – Add your snippet!


Join the discussion!