Skip to content

Instantly share code, notes, and snippets.

@corypina
Last active May 20, 2020 05:16
Show Gist options
  • Save corypina/8d3c3a45c136f6e97b4297f2ee40aaf0 to your computer and use it in GitHub Desktop.
Save corypina/8d3c3a45c136f6e97b4297f2ee40aaf0 to your computer and use it in GitHub Desktop.
Use a custom taxonomy term to hide posts from main queries
<?php
// Hide custom taxonomy term from all queries
// Still accessible via direct link
add_action('pre_get_posts', function($query){
if ( $query->is_home() || $query->is_feed() || $query->is_search() || $query->is_archive() ) {
$tax_query = array(
array(
'taxonomy' => 'admin_category', // taxonomy name
'field' => 'slug',
'terms' => 'hidden', // taxonomy slug
'operator' => 'NOT IN',
)
);
$query->set( 'tax_query', $tax_query );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment