Support » Plugin: Advance WP Query Search Filter » Exclude category from search results

  • Hi Ron

    Was wondering if it is possible to exclude a category from the search results.

    I am using custom fields on my posts which is working well with complex searches and filtering – but because of the “search all” option on all fields – it does mean if no field is actually selected all my posts are displayed. (if search is clicked of course)

    Was wondering if I could use the “compare” option to exclude a category from being displayed?

    Any ideas would be appreciated – (I am using shortcode)
    Thanks again

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author TC.K


    No you cant use compare operator to do that. I am afraid there are no easy way to do it.

    Why don’t you adding another field for category? So that user can choose from which category he/she want to search for?

    Hi Ron
    Thanks for your reply.

    I have three fields in my search at the moment

    e.g for my needs visitors can sort by price, location and type – unfortunately by clicking search without selecting anything brings up all posts – some of which have nothing to do with the search.

    Is there away to make one of the field values the default – rather than all records?

    Kind regards


    Plugin Author TC.K


    So far if you want to make one of the field selected by default, you have to options:
    1. editing the plugin file,
    2. by javascript.

    Renzo Bassi


    Try to insert the next code in include>process.php line 158 to exclude category 2, 3 and 4.

    $query->set( 'cat', '-2,-3,-4' ); // category ids to exclude

    Not sure if this is relevant to your problem, but this workaround solved a problem for me. I wanted people to search in a single category. But I didn’t want them to have to choose that category in a field. I wanted that category selected by default.

    Here’s the workaround:

    Add a drop-down field for category, and exclude all the categories except the one you want. Leave the ALL option blank. This way you will have the one category only selected. Build the rest of your search fields. Then use the CSS to hide the category field.

    Now your form searches in one cateogry, and it’s automatic. You haven’t been forced to choose it.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Exclude category from search results’ is closed to new replies.