Created
June 19, 2019 12:33
-
-
Save Asikur22/2f8b6b05995012f3032fb439cd18751b to your computer and use it in GitHub Desktop.
Show Specific Category Post on Custom Post Type Archive Page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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