include custom post types categories to the main query

Solutions on MaxInterview for include custom post types categories to the main query by the best coders in the world

showing results for - "include custom post types categories to the main query"
Blaire
23 May 2019
1function custom_post_type_cat_filter($query) {
2  if ( !is_admin() && $query->is_main_query() ) {
3    if ($query->is_category()) {
4      $query->set( 'post_type', array( 'post', 'YOUR CPT' ) );
5    }
6  }
7}
8
9add_action('pre_get_posts','custom_post_type_cat_filter');
10