Ready to get started?Download WordPress


exclude from search (1 post)

  1. kortschot
    Posted 2 years ago #

    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;

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

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

    I tried


    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.



Topic Closed

This topic has been closed to new replies.

About this Topic