Last active
May 20, 2020 05:16
-
-
Save corypina/8d3c3a45c136f6e97b4297f2ee40aaf0 to your computer and use it in GitHub Desktop.
Use a custom taxonomy term to hide posts from main queries
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 | |
// 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