• We are configuring the search (free version) on one of a clients WooCommerce website on just products. We are using the default operator for search – AND require all terms with Disable or Fallback unchecked. What I would like to know if it is possible when no exact search results appear it can display a different title so people know that they are not seeing the exact match searches. Currently if someone searches for say ‘Lee Jeans’ (currently no products) they get a number of results then appearing for just ‘Jeans’

    This could be a bit misleading so it would be great if there was a way to show above the fallback results something like ‘No exact matches, you might like these Products instead..’

    Is this possible?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    It is possible. You have to add a filter that checks to see if the operator is set to OR:

    add_filter('relevanssi_search_filters', 'check_for_or');
    function check_for_or($args) {
        global $relevanssi_fell_back_to_or;
        if ($args['operator'] == "OR") $relevanssi_fell_back_to_or = true;
        return $args;
    }

    Now we know if the operator was OR during the search. Then on the search results template, just make that known:

    global $relevanssi_fell_back_to_or;
    if ($relevanssi_fell_back_to_or) echo "No exact matches, you might like these products instead...";
    Thread Starter dreamabstract

    (@dreamabstract)

    That worked perfectly, if we wanted to hide this part ’11 results found for ‘lee jeans” when the fallback kicks in, how would we go about that?

    Currently we have:

    <?php
            global $wp_query;
    		global $relevanssi_fell_back_to_or;
    if ($relevanssi_fell_back_to_or) echo "No exact matches, you might like these products instead...";
            $number_of_results = $wp_query->found_posts;
            ?>
    Plugin Author Mikko Saari

    (@msaari)

    Wrap it in a

    if (!$relevanssi_fell_back_to_or) {
    
    }

    block.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Fallback search – Title’ is closed to new replies.