Function ‘hide category’ removes my category in admin too
-
I have 3 categories: APP NEWS / NEWS / FEATURED I wanted to display on front-end all posts with NEWS category but also if I have 1 post with 2 categories it’s display too but with NEWS category tag. So I puted on my function file:
add_filter('get_the_terms', 'hide_categories_terms', 10, 3); function hide_categories_terms($terms, $post_id, $taxonomy){ // list of category slug to exclude, $exclude = array('featured', 'app-news'); if (!is_admin()) { foreach($terms as $key => $term){ if($term->taxonomy == "category"){ if(in_array($term->slug, $exclude)) unset($terms[$key]); } } } return $terms; }
but in administration when I make a change to an article and re-register it automatically deletes the assignment to the category featured or app news, except I need it anyway. Yet I have specified ‘if (!is_admin())’, I don’t understand…
Someone have an idea please?
Have a great day!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Function ‘hide category’ removes my category in admin too’ is closed to new replies.