Answers for "Include Custom Post Types Categories to the main query"

PHP
0

Include Custom Post Types Categories to the main query

function custom_post_type_cat_filter($query) {
  if ( !is_admin() && $query->is_main_query() ) {
    if ($query->is_category()) {
      $query->set( 'post_type', array( 'post', 'YOUR CPT' ) );
    }
  }
}

add_action('pre_get_posts','custom_post_type_cat_filter');
Posted by: Guest on June-20-2021

Code answers related to "Include Custom Post Types Categories to the main query"

Browse Popular Code Answers by Language