Created
May 15, 2022 21:41
-
-
Save janboddez/039f704236b6ebd3df12e82e1c7a3416 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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