Tagged: ,

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #775911

    Hi, Gianluca from Italy.
    Need to hide name categories from posts everywhere in my site mfm.it/demo for example category TOP. Simply hide the category, non the post belongs to it.
    I found a thread dated 2012 (https://kriesi.at/support/topic/hide-a-category-from-blog/) but i thin now it’s obsolete. Can u help me please? I have alrealdy a child theme. Thanks in adavance, Gianluca

    #775923

    Hey sitibus,

    This answer should help you: http://wordpress.stackexchange.com/questions/181182/hide-a-certain-category-name-without-removing-it

    Best regards,
    John Torvik

    #776168

    Hi, I’ve read and understood that i have to put in my functions.php thise code is it right?

    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(6);

    // 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 where do I have to set the IDs of the categories (such as 34, 45) ?

    Thanks again Gianluca

    #776451

    Hi,

    That should be this line:

    $excludeIDs = array(6);

    So in your case it would be something like this:

    $excludeIDs = array(34, 45);

    Best regards,
    Rikard

    #778984

    Sorry again but it doesn’t work as you can see at http://www.mfm.it/demo/
    I added the 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(6960, 7097);

    // 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;
    }

    where 6960 and 7097 are the IDs of categories TOP & DISCOVER but as you can see those taxonomies are still visible.

    Please help me. Thanks Gianluca

    #779823

    Hi,

    What is the blog layout that you’re using? Please replace the filter with the following.

    add_filter('get_the_terms', 'hide_categories_terms', 10, 3);
    function hide_categories_terms($terms, $post_id, $taxonomy){
    	$exclude = array(6, 2, 3);
    
        if (!is_admin()) {
            foreach($terms as $key => $term){
                if(in_array($term->term_id, $exclude)) unset($terms[$key]);
            }
        }
        return $terms;
    }

    In the $exclude variable, add the id of the term that you want to exclude.

    Best regards,
    Ismael

    #779927

    Hi Ismael
    great job, it works perfectly.
    Wonderful :-)))

    #779939

    Hi Gianluca,
    We’re glad the code worked for you! Please let us know here in the forums if you need help with anything else.

    Cheers,
    Sarah

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘Hide specific categories from meta’ is closed to new replies.