Created
October 1, 2013 23:52
-
-
Save hissy/6787018 to your computer and use it in GitHub Desktop.
[WordPress/Filter] Exclude specific category from your blog
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 'example' category from your blog | |
function my_get_terms_args_exclude( $args, $taxonomies ) { | |
if (!is_admin()) { | |
$cat = get_category_by_slug( 'example' ); | |
if ( is_object( $cat ) ) { | |
$args['exclude'] = $cat->term_id; | |
} | |
} | |
return $args; | |
} | |
add_filter( 'get_terms_args', 'my_get_terms_args_exclude', 10, 2 ); | |
function my_get_the_terms_exclude( $terms, $post_id, $taxonomy ) { | |
if (!is_admin() && is_array($terms)) { | |
$_terms = array(); | |
foreach( $terms as $key => $term ) { | |
if ($term->slug != 'example' ) { | |
$_terms[$key] = $term; | |
} | |
} | |
$terms = $_terms; | |
unset($_terms); | |
} | |
return $terms; | |
} | |
add_filter( 'get_the_terms', 'my_get_the_terms_exclude', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment