Last active
June 8, 2018 00:05
-
-
Save ngearing/0674f1a0e25e54f15e5f676b08bdb5b4 to your computer and use it in GitHub Desktop.
Exclude terms in term lists from non Admins in WordPress
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 | |
/** | |
* Exclude some terms from the term lists. | |
* | |
* @param WP_Term_Query $term_query The class instance instance. | |
* @return void | |
*/ | |
function exclude_terms( $term_query ) { | |
if ( | |
is_feed() || | |
current_user_can( 'edit_users' ) | |
) { | |
return; | |
} | |
$taxonomy = 'tribe_events_cat'; // taxonomy. | |
$terms_to_exclude = [ '277' ]; // term ids. | |
if ( in_array( $taxonomy, $term_query->query_vars['taxonomy'] ) ) { | |
$term_excludes = $term_query->query_vars['exclude']; | |
$term_excludes = array_merge( is_array( $term_excludes ) ? $term_excludes : [], $terms_to_exclude ); | |
$term_query->query_vars['exclude'] = $term_excludes; | |
} | |
} | |
add_action( 'pre_get_terms', 'exclude_terms' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment