• Hello,

    I noticed that product search in admin is not working because the relevanssi function seems to be ignored and the default search_products CRUD function (since WC3.0) is used instead. Other post types are working for me (posts/pages admin), but products are not.

    Any idea how to solve it?

    Thanks.

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

    (@msaari)

    I’ve had conflicting results with WooCommerce product search in admin. When I test it, it works perfectly fine, but I’ve had someone say it doesn’t work – and I can’t really tell what’s different.

    Just to make sure: you’re talking about the search on the /wp-admin/edit.php?post_type=product page, right?

    Thread Starter Martin Šnajdr

    (@martin-snajdr)

    Thank you for your response.

    Yes, that is the page. I tried to disable all plugins – except Relevanssi, WooCommerce and Query Monitor (I’m running WP 4.9.5, WooCommerce 3.3.4, Relevanssi 4.0.7 and Query Monitor 2.17.0) and I still got this problem.

    When I search for a post in admin /wp-admin/edit.php, the QM show, that the relevanssi_search function was used for searching, when I search for products on /wp-admin/edit.php?post_type=product, QM shows that WC_Product_Data_Store_CPT->search_products() function was used.

    Plugin Author Mikko Saari

    (@msaari)

    Ah, I was on an older version of WooCommerce (3.2.3). I updated to 3.3.4 now, and yeah, I’m seeing the search_products() function now.

    Try this:

    add_filter( 'relevanssi_search_ok', 'rlv_product_search_override', 10, 2 );
    function rlv_product_search_override( $ok, $query ) {
        if ( isset( $query->query_vars['product_search'] ) ) $ok = true;
        return $ok;
    }
    
    add_filter( 'relevanssi_modify_wp_query', 'rlv_product_search_modify' );
    function rlv_product_search_modify( $query ) {
    	if ( isset( $query->query_vars['product_search'] ) ) {
    		$s = $_GET['s'];
    		$query->set( 's', $s );
    	}
    	return $query;
    }

    These should allow Relevanssi to override the WooCommerce search.

    Thread Starter Martin Šnajdr

    (@martin-snajdr)

    Well I tried your fix, but I still can’t get it working. It seems that QM now shows relevanssi_search query (but also the default WooCommerce search query), but the search is not returning any results. I have some custom fields (we are using something like custom second type of product SKU) specified directly in Relevanssi settings, it works perfectly outside admin (I search for specific secondary SKU, it returns single product), but still not returning any results in admin. It seems that the search_products function is still somehow overriding the final results or I don’t know…

    Plugin Author Mikko Saari

    (@msaari)

    This worked for me – tried searching for author name, which the default WC search can’t find. But perhaps there’s some filters in place somewhere? I’d look at what $query->query_vars contains in the rlv_product_search_modify() filter.

    Hi, I have the same problem and added your fix with the two add_filter(). What happens is that with the fix I can now se, that the search finds for example “387 kohdetta”, but in the list only “Etsittyä tuotetta ei löytynyt”, so it appears that the search finds the products but cannot list them in admin.

    Plugin Author Mikko Saari

    (@msaari)

    I did a search in the product admin page and I’m seeing this as the Relevanssi query:

    SELECT DISTINCT(relevanssi.doc), relevanssi.*, relevanssi.title * 5 + relevanssi.content * 1 + relevanssi.comment * 0.75 + relevanssi.tag * 0.75 + relevanssi.link * 0 + relevanssi.author + relevanssi.category * 0.75 + relevanssi.excerpt + relevanssi.taxonomy + relevanssi.customfield + relevanssi.mysqlcolumn AS tf 
    FROM wp_relevanssi AS relevanssi 
    WHERE relevanssi.term = 'vihreä' 
    AND relevanssi.doc IN (2270,2221,0)
    AND ( relevanssi.doc IN ( 
    SELECT DISTINCT(posts.ID)
    FROM wp_posts AS posts 
    WHERE posts.post_type IN ('product') ) )

    There’s AND relevanssi.doc IN (2270,2221,0) at least coming from somewhere in WooCommerce, so looks like WooCommerce is adding an extra post__in parameter there. You may want to try blocking that:

    add_filter( 'relevanssi_search_ok', 'rlv_product_search_override', 10, 2 );
    function rlv_product_search_override( $ok, $query ) {
        if ( isset( $query->query_vars['product_search'] ) ) $ok = true;
        return $ok;
    }
    
    add_filter( 'relevanssi_modify_wp_query', 'rlv_product_search_modify' );
    function rlv_product_search_modify( $query ) {
    	if ( isset( $query->query_vars['product_search'] ) ) {
    		$s = $_GET['s'];
    		$query->set( 's', $s );
    		$query->set( 'post__in', array() );
    	}
    	return $query;
    }

    If that doesn’t help, when inside the rlv_product_search_modify() function, add a var_dump( $query->query_vars ); and let me know what that prints out.

    it works for me thanks

    I get some results, but not the correct ones. With the same search as I mentioned above, I still se “387 kohdetta” but the search results print out 10 hits. The search is paginated but when going to page 2 of the search results, it shows “Etsittyä tuotetta ei löytynyt”

    The var dump:

    array(66) {
      ["paged"]=>
      int(1)
      ["post_type"]=>
      string(7) "product"
      ["product_type"]=>
      string(0) ""
      ["posts_per_page"]=>
      int(50)
      ["post__in"]=>
      array(0) {
      }
      ["product_search"]=>
      bool(true)
      ["error"]=>
      string(0) ""
      ["m"]=>
      string(0) ""
      ["p"]=>
      int(0)
      ["post_parent"]=>
      string(0) ""
      ["subpost"]=>
      string(0) ""
      ["subpost_id"]=>
      string(0) ""
      ["attachment"]=>
      string(0) ""
      ["attachment_id"]=>
      int(0)
      ["name"]=>
      string(0) ""
      ["static"]=>
      string(0) ""
      ["pagename"]=>
      string(0) ""
      ["page_id"]=>
      int(0)
      ["second"]=>
      string(0) ""
      ["minute"]=>
      string(0) ""
      ["hour"]=>
      string(0) ""
      ["day"]=>
      int(0)
      ["monthnum"]=>
      int(0)
      ["year"]=>
      int(0)
      ["w"]=>
      int(0)
      ["category_name"]=>
      string(0) ""
      ["tag"]=>
      string(0) ""
      ["cat"]=>
      string(0) ""
      ["tag_id"]=>
      string(0) ""
      ["author"]=>
      string(0) ""
      ["author_name"]=>
      string(0) ""
      ["feed"]=>
      string(0) ""
      ["tb"]=>
      string(0) ""
      ["meta_key"]=>
      string(0) ""
      ["meta_value"]=>
      string(0) ""
      ["preview"]=>
      string(0) ""
      ["s"]=>
      string(12) "195/60 conti"
      ["sentence"]=>
      string(0) ""
      ["title"]=>
      string(0) ""
      ["fields"]=>
      string(0) ""
      ["menu_order"]=>
      string(0) ""
      ["embed"]=>
      string(0) ""
      ["category__in"]=>
      array(0) {
      }
      ["category__not_in"]=>
      array(0) {
      }
      ["category__and"]=>
      array(0) {
      }
      ["post__not_in"]=>
      array(0) {
      }
      ["post_name__in"]=>
      array(0) {
      }
      ["tag__in"]=>
      array(0) {
      }
      ["tag__not_in"]=>
      array(0) {
      }
      ["tag__and"]=>
      array(0) {
      }
      ["tag_slug__in"]=>
      array(0) {
      }
      ["tag_slug__and"]=>
      array(0) {
      }
      ["post_parent__in"]=>
      array(0) {
      }
      ["post_parent__not_in"]=>
      array(0) {
      }
      ["author__in"]=>
      array(0) {
      }
      ["author__not_in"]=>
      array(0) {
      }
      ["ignore_sticky_posts"]=>
      bool(false)
      ["suppress_filters"]=>
      bool(false)
      ["cache_results"]=>
      bool(true)
      ["update_post_term_cache"]=>
      bool(true)
      ["lazy_load_term_meta"]=>
      bool(true)
      ["update_post_meta_cache"]=>
      bool(true)
      ["nopaging"]=>
      bool(false)
      ["comments_per_page"]=>
      string(2) "50"
      ["no_found_rows"]=>
      bool(false)
      ["order"]=>
      string(4) "DESC"
    }
    
    
    Plugin Author Mikko Saari

    (@msaari)

    @ckarlsson, if you do the same search on the front end, how many results you get? 387 or 10? It’s possible Relevanssi finds the ten results, while WP default search finds 387, and that’s why there’s a mismatch.

    At least those search parameters have nothing unusual in them.

    In the front end I get 238 results…So something strange is happening.

    Noticed that woocommerce had an update to 3.5.5, but it did not help the situation.

    Can I create a user for you so you can log in and see for your self?

    Plugin Author Mikko Saari

    (@msaari)

    Sorry, that’s a level of support I can’t provide for the users of the free version.

    Thread Starter Martin Šnajdr

    (@martin-snajdr)

    Well after a lot of hours of looking for a solution I realized, that I didn’t implemented your solution with all plugins deactivated. So I deactivated them all (except WooCommerce and Relavanssi) and I found out there is some kind of bug in Yoast SEO plugin. If I turn off the “Text link counter” Yoast SEO feature and it works!!!

    Mysteries of the WP universe I guess 😀

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘WooCommerce admin product search not working’ is closed to new replies.