Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Last active December 7, 2017 08:04
Show Gist options
  • Save obiPlabon/34bb9b4efb1587fb3c57d90330e8125e to your computer and use it in GitHub Desktop.
Save obiPlabon/34bb9b4efb1587fb3c57d90330e8125e to your computer and use it in GitHub Desktop.
<?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