Last active
December 7, 2017 08:04
-
-
Save obiPlabon/34bb9b4efb1587fb3c57d90330e8125e to your computer and use it in GitHub Desktop.
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
| <?php | |
| /** | |
| * Show posts which are only under uncategorized term | |
| * 1 is the id of Uncategorized term | |
| */ | |
| function op_show_only_uncategorized( $query ) { | |
| if ( is_admin() || ! $query->is_main_query() || ! $query->is_category( 1 ) ) { | |
| return; | |
| } | |
| // Query all the category terms excluding Uncategorized term | |
| $categories = get_categories( array( | |
| 'exclude' => '1', | |
| 'fields' => 'id=>slug' | |
| ) ); | |
| $query->set( 'category__not_in', array_keys( $categories ) ); | |
| } | |
| add_action( 'pre_get_posts', 'op_show_only_uncategorized' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment