Last active
January 29, 2017 18:07
-
-
Save carasmo/c5e80c22ea00604187f653999569b6ac to your computer and use it in GitHub Desktop.
Exclude Categories from the post_meta output
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 | |
//don't add | |
/** | |
* | |
* Exclude Terms by ID from the get_the_category_list(); (WordPress core) | |
* Ref: http://stackoverflow.com/a/34817401/1004312 | |
* I add a post to two categories with the ids (examples) 200 and 266 | |
* but I only want 200 in the post_meta shortcode in Genesis | |
* which uses the get_the_category_list(); (WordPress core) which has no filter | |
* But that uses uses get_the_terms(); (WordPress core) which does have a filter | |
* The problems this leads to is that if 266 is a main category for some other post, it won't show. | |
* | |
* This is not recommended, instead just assign posts to a single category and use tags | |
* | |
*/ | |
function yourprefix_exclude_terms( $terms ) { | |
// put term ids here comma separated | |
$exclude_terms = array( 266 ); | |
if (!empty( $terms ) && is_array( $terms ) ) { | |
foreach ($terms as $key => $term ) { | |
if (in_array( $term->term_id, $exclude_terms ) ) { | |
unset( $terms[ $key ] ); | |
} | |
} | |
} | |
return $terms; | |
} | |
add_filter( 'get_the_terms', 'yourprefix_exclude_terms' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment