Reputation: 8233
I'm using a theme for a customer.
To display post taxonomies, the theme use the_terms(). It is working well. But I have a featured category that I do not want to display. So basically, I need something to check if the current term != "featured" for that function (the_terms() is used on the whole templates).
I read the codex ( http://codex.wordpress.org/Function_Reference/the_terms#Parameters ), but there's nothing about excluding particular terms...
The code (not helpful but someone asked me):
<?php the_terms($post->ID, 'portfolio_category', '', ', ', ''); ?>
Any help ?
EDIT : Now I can filter the terms with :
add_filter('get_the_terms', 'modify_term_list', 1);
function modify_term_list($terms){
foreach($terms as $term_index => $term_object){
if($term_object->name === 'A la une'){
unset($terms[$term_index]);
return $terms;
}
}
}
The term "A la Une" (featured) is not displaying no more. But on the 4 terms I got, only one is now displayed.
Upvotes: 1
Views: 1683
Reputation: 8233
Based on boom_Shiva's code :
add_filter('get_the_terms', 'modify_term_list', 1);
function modify_term_list($terms){
foreach($terms as $term_index => $term_object){
if($term_object->name === 'A la une'){
unset($terms[$term_index]);
}
else {
return $terms;
}
}
}
Upvotes: 0
Reputation: 785
This code is to not list a particular term like "Test"
add_filter('get_the_terms', 'modify_term_list', 1);
function modify_term_list($terms){
foreach($terms as $term_index => $term_object){
if($term_object->name == 'Test'){
unset($terms[$term_index]);
return $terms;
}
}
}
You can replace the "Test" with your TERM NAME
Upvotes: 1