Skip to content

Instantly share code, notes, and snippets.

@Asikur22
Created June 19, 2019 12:33
Show Gist options
  • Select an option

  • Save Asikur22/2f8b6b05995012f3032fb439cd18751b to your computer and use it in GitHub Desktop.

Select an option

Save Asikur22/2f8b6b05995012f3032fb439cd18751b to your computer and use it in GitHub Desktop.
Show Specific Category Post on Custom Post Type Archive Page
/*
* Show Only One Category on Archive Page.
*/
function wp98_pre_get_posts( $query ) {
if ( is_post_type_archive( 'cpt_services' ) && $query->is_main_query() ) {
$query->set(
'tax_query', array(
array(
'taxonomy' => 'cpt_services_group',
'terms' => 'menu',
'field' => 'slug',
'operator' => 'IN'
)
)
);
}
}
add_action( 'pre_get_posts', 'wp98_pre_get_posts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment