i have the following schematic:
the world
- Cover the world.
The country
-Covered the country.
theater
- theater cover.
etc...
And I want that when I select any of the child categories the parent category appears.
my code:
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;
}
but just hide the child category.