Skip to content

Instantly share code, notes, and snippets.

@janboddez
Created May 15, 2022 21:41
Show Gist options
  • Save janboddez/039f704236b6ebd3df12e82e1c7a3416 to your computer and use it in GitHub Desktop.
Save janboddez/039f704236b6ebd3df12e82e1c7a3416 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'pre_get_posts', function( $query ) {
if ( is_admin() ) {
return $query;
}
if ( is_feed() ) {
return $query;
}
// Exclude everywhere but admin pages and feeds.
$cat = get_category_by_slug( 'rss' ); // Your "hidden" category's slug.
$query->set( 'cat', '-' . $cat->term_id ); // Could probably also use `category__not_in`, but whatevs.
// Now, this would probably not yet exclude the (now seemingly empty) "rss"
// category from, e.g., the category list widget. (Is that a thing, still?)
// But doing so would be easy enough, too.
return $query;
}, 9999 ); // Because who knows what other callbacks are being run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment