Advance WP Query Search Filter
Exclude category from search results (6 posts)

  1. brad1004
    Posted 2 years ago #

    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


  2. TC.K
    Plugin Author

    Posted 2 years ago #

    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?

  3. brad1004
    Posted 2 years ago #

    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


  4. TC.K
    Plugin Author

    Posted 2 years ago #

    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.

  5. Renzo Bassi
    Posted 2 years ago #

    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

  6. dherold
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Advance WP Query Search Filter
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic