Reply To: AND Logic Operator not working properly

Home Forums Product Support Forums Ajax Search Pro for WordPress Support AND Logic Operator not working properly Reply To: AND Logic Operator not working properly


Ernest Marcinko

Hi Fanuel,

Sorry about the delay, but I had to make sure I come up with a solution on my test servers first, before going on testing it on yours.

I believe I have found a solution. I’ve made it to a new option as well:
As a test, I have selected ‘Female’ and ‘Faculty’, and there are only results that match at least BOTH of these categories (or others too, but these 2 must match).
As a counter example, if I choose ‘Male’, ‘Female’ and ‘Faculty’, there is a contradiction, as no posts match all 3 categories, so no results are shown.

There is however a small issue there (but I solved it as well): I see you have the ‘Sex’ and the ‘Who Is’ categories also in the filter list, but there are no posts within those categories. Meaning if you choose any of them, then no results will be shown – because the logic now strictly displays results that match ALL of the categories exactly, but since there are no items within those, nothing will show.

One solution is to simply not use those at all, another is to place everything that is in male or female into the ‘Sex’ parent category as well, but that could take some time.
There is a third solution, and since you gave me FTP access, I have made a custom filter code, which I placed to the functions.php file in your active theme directory. This code basically detects if the ‘Sex’ or the ‘Who is’ category is selected, and removes them from the actual filter code, solving this problem. For future reference, this is the code I have placed there:

add_filter('asp_query_args', 'asp_change_tax_query_args', 10, 3);
function asp_change_tax_query_args($args, $search_id, $options) {
  $remove = array(128, 122);
  if ( is_array($args['post_tax_filter']) ) {
    foreach ( $args['post_tax_filter'] as $k=>&$v ) {
      if ( is_array($v['include']) && $v['taxonomy'] == 'category' ) {
        $v['include'] = array_diff($v['include'], $remove);
  return $args;

Now the search should display results that match all the selected categories, and if any of the selected ones does not match the potential result, it will not show up.

I hope this helps!

Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)