Reply To: Search with categories 'OR' vs. 'AND'

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Search with categories 'OR' vs. 'AND' Reply To: Search with categories 'OR' vs. 'AND'

#4716
Ernest Marcinko
Ernest Marcinko
Keymaster

Hi!

The logic is changeable, but it’s from an exclusion viewpoint for various reasons. (mostly because of how wordpress stores terms) By default it’s the AND logic that’s used, but it’s connected only with the exclusions.
I’m working on an update which will have a wider selection of term logics with a documentation as well.

Until then the best possible thing to do is to make a minor modification to the code to force an AND logic on the non-excluded categories.

1. Open up the plugins/ajax-search-pro/includes/search_content.class.php file
2. Go to lines 182-188, where you should see this:


if (count($all_terms) > 0) {
    $words = '--' . implode('--|--', $all_terms) . '--';
    if ($term_logic == 'and')
        $term_query = "HAVING (ttid NOT REGEXP '$words')";
    else
        $term_query = "HAVING (ttid REGEXP '$words')";
}

3. Modify those lines to this:


if (count($all_terms) > 0) {
    $term_query = "HAVING (ttid REGEXP '--" . implode("--' AND ttid REGEXP '--", $all_terms) . "--')";
}

Now, if you have all the other categories excluded but those two on the Advanced options panel, then this should probably work.

Best,
Ernest Marcinko

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