Search Function Not Working - Slider Revolution

Hi there - Our site uses Theme X with a custom child theme, Cornerstone and Woocommerce. Recently the search function has stopped working properly. Specifically, it only returns search results some of the time.

Luckily we have a dev site that has a copy of the live site. The copy is always a few weeks old. So I made a backup of the dev site and started to update each plugin one by one. Then I updated to the latest Themeco theme and Cornerstone. Search still functioned. Then I updated Slider Revolution. Once I updated Slider Revolution and I opened a new incognito window to test search. The first thing I saw was this message. (See attachment)

Without taking any action I tested the search function and it did not work.

I looked under the Slider Revolution trying to find the Troubleshoot set option as mentioned in the error message but did not see it.

To test further, I deactivated Slider Revolution and tested search again. Search still did not work.

Then I removed Slider Revolution from the plugins list. Then I tested search again and search still did not work.

Any suggestions at this point? Based on testing, I would say its Slider Revolution. But considering I have removed the plugin, I would assume it would no longer affect the search function. Unless of course the issue involves the jquery.js as mentioned in the attached image.

Here is the link to the dev site. https://devawpny.wpengine.com/ Note, we use a custom ajax search that our developer created. When I contacted them, they suggest we go through the troubleshooting steps I mentioned above.

Any insights are appreciated.

Thanks
Tim

Hello Tim,

I have tested your staging site and I can confirm that the search is not working. Do you want some custom search functions added in the child theme? Please provide us access to your site so that we can check your settings and fixed the issue. Please create a secure note with the following info:
– Link to your site
– WordPress Admin username / password

To know how to create a secure note, please check this out: https://theme.co/apex/forum/t/how-to-get-support/288

Thank you in advance.

Hi @RueNel

I am not explaining things well.

  1. Search is not working as you confirmed
  2. Our search feature was working until recently. Unfortunately I can’t associate it with a specific update other than through testing.
  3. Our search feature is a custom search feature our developer created. So we do not need a new search feature added to the theme. Unless of course it is determined that the search feature is deprecated.
  4. I went through another series of testing. Specifically I reverted our developer site to a version within which search worked. Then I started to update all the plugins. After updating each plugin I cleared all caches and then tried search in an incognito window.

This time search stopped working after I updated Cornerstone. I then updated any remaining plugins thinking this might resolve the issue, it did not.

At this point I am unsure what might be causing the issue.

I can create a set of credentials for our site and share them via the secure notes feature.

Before I do that, I need to know whether:

  1. Do you want to work with an exact copy of our live site? If so, I can copy that onto our development server.

OR

  1. Do you want to work with the last known working version of the site. This version would be a few weeks old.

Thanks
Tim

Hello Tim,

It is best that we work on the current live site. Please have it cloned and send us the WP credentials so we can login and investigate the search issue.

Best Regards.

@RueNel

I have cloned the live site over to the development site.

I have created credentials for you and shared them via the secure note.

Thanks
Tim

Hello Tim,

I have logged in and I stumbled this custom PHP code that affects the search functionality in your site.

// Search on custom fields

// Join posts and postsmeta tables
add_filter('posts_join', 'mitegen_custom_fields_search_join' );

function mitegen_custom_fields_search_join( $join ) {
    global $wpdb;

    if ( is_search() ) {
        $join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
    }

    return $join;
}

// Modify the search query
add_filter( 'posts_where', 'mitegen_custom_fields_search_where' );

function mitegen_custom_fields_search_where( $where ) {
    global $pagenow, $wpdb;

    if ( is_search() ) {
        $where = preg_replace(
            "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
            "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
    }

    return $where;
}

// Prevent duplicates
add_filter( 'posts_distinct', 'mitegen_custom_fields_search_distinct' );

function mitegen_custom_fields_search_distinct( $where ) {
    global $wpdb;

    if ( is_search() ) {
        return "DISTINCT";
    }

    return $where;
}

// Exclude 'hidden' products from search
add_action('pre_get_posts', 'mitegen_hide_hidden_products_from_search');

function mitegen_hide_hidden_products_from_search($query) {
  if (!is_admin() && $query->is_main_query()) {
    if ($query->is_search) {
      $args = array(
        'post_type' => 'product',
        'posts_per_page' => -1,
        'fields' => 'ids',
        'tax_query' => array(
          array(
            'taxonomy' => 'product_visibility',
            'field'    => 'name',
            'terms'    => 'exclude-from-search',
            'operator' => 'IN',
          )
        )
      );

      $excluded_ids = get_posts($args);

      $query->set('post__not_in', $excluded_ids);
    }
  }
}

I have switched to the parent theme and did a search. It display several items as a result. I therefore conclude that your child theme and your custom php functions were causing the issue. I would highly recommend that you consult with the creator of these codes to resolve this search issues.

Kindly let us know how it goes.

1 Like

@RueNel - Thank you for the help. I will reach out to our developer.

Hello Tim,

You are most welcome. Sure, I have unlisted the thread so it won’t show up on the ticket list.

Thanks.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.