• Hé there,

    Got a little PHP question..

    I want to exclude a category from my search results. But can’t do it by ID.

    function myFunctionName($query)
    
    {
    if ($query->is_search)
    {
    $query->set('cat','-'.$get_cat_id('category name').'');
    }
    return $query;
    }
    add_filter('pre_get_posts','myFunctionName');

    I’m not a php wizard.. but i’m guessing the snag is in:

    $query->set('cat','-'.$get_cat_id('category name').'');

    I tried

    $query->set('cat','-24');

    Which works, but since I have some more installations of the same theme coming in the next month’s I want it to work on the category name instead of the ID. Due the ID won’t be the same in every installation and the name will.

    Thanks!

    Paul

The topic ‘exclude from search’ is closed to new replies.