我有以下示意图:
the world
- Cover the world.
The country
-Covered the country.
theater
- theater cover.
etc...
我希望当我选择任何子类别时,父类别都会出现。我的代码:
add_filter(\'get_the_terms\', \'hide_categories_terms\', 10, 3);
function hide_categories_terms($terms, $post_id, $taxonomy){
// define which category IDs you want to hide
$excludeIDs = array(31, 32, 33, 34, 35, 36, 37, 38, 96);
// get all the terms
$exclude = array();
foreach ($excludeIDs as $id) {
$exclude[] = get_term_by(\'id\', $id, \'category\');
}
// filter the categories
if (!is_admin()) {
foreach($terms as $key => $term){
if($term->taxonomy == "category"){
foreach ($exclude as $exKey => $exTerm) {
if($term->term_id == $exTerm->term_id) unset($terms[$key]);
}
}
}
}
return $terms;
}
但只需隐藏子类别。