• Resolved pickme

    (@pickme)


    Hello,

    I added the following code:

    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;
    }

    within functions.php of the child theme and also ticked option for admin search under ‘Searching’ Tab.

    Is there a way for the product’s admin page at wp-admin/edit.php?post_type=product to search for attribute taxonomies using Woocommerce 4.6.2 ?

    Thanks!

    • This topic was modified 4 years ago by pickme.
    • This topic was modified 4 years ago by pickme.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Mikko Saari

    (@msaari)

    What you have there almost worked for me. Changing the second function to this made it work:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_product_search_modify' );
    function rlv_product_search_modify( $query ) {
    	if ( 'product' === $query->query_vars['post_type'] ) {
    		unset( $query->query_vars['post__in'] );
    		$query->query_vars['s'] = $_REQUEST['s'];
    	}
    	return $query;
    }

    For some reason there was a post__in parameter set to “0” and “0”, which was blocking all the posts.

    Thread Starter pickme

    (@pickme)

    Thank you @msaari !

    This worked!

    Regards

    Thread Starter pickme

    (@pickme)

    The code unfortunately interferes with the frontend search and while admin search works fine, the frontend search does not give the right results according to the term provided to it.

    Why?

    Thank you

    • This reply was modified 4 years ago by pickme.
    • This reply was modified 4 years ago by pickme.
    • This reply was modified 4 years ago by pickme.
    Plugin Author Mikko Saari

    (@msaari)

    How exactly is this interfering with the front end search? What is happening? How are the results wrong?

    The filter can be restricted to just admin searches:

    add_filter( 'relevanssi_modify_wp_query', 'rlv_product_search_modify' );
    function rlv_product_search_modify( $query ) {
    	if ( is_admin() && isset( $query->query_vars['product_search'] ) ) {
    		unset( $query->query_vars['post__in'] );
    		$query->query_vars['s'] = $_REQUEST['s'];
    	}
    	return $query;
    }
    Thread Starter pickme

    (@pickme)

    Hello @msaari

    Restricting the second filter to only admin search solved it.

    Therefore adding the last function you provided together with the top one works best.

    The issue with the previous filter was this:

    When the code was added, the admin search was functioning properly returning correct results of taxonomy term searches. On the other hand, the front end search bar of the site was returning totally irrelevant results when inputing a whole word even though existing as a taxonomy. Moreover, indexed taxonomy terms were not provided in the search results.

    Strangely, nothing to do with the issue described above and without the code, is it normal for ‘Admin search : Use Relevanssi for admin searches’ to be clicked in order for the front end search to provide taxnonomy results when provided in the search field? It does not when unticked. I thought that this setting was only intended for WP backend.

    Regards

    • This reply was modified 4 years ago by pickme.
    • This reply was modified 4 years ago by pickme.
    • This reply was modified 4 years ago by pickme.
    • This reply was modified 4 years ago by pickme.
    • This reply was modified 4 years ago by pickme.
    Plugin Author Mikko Saari

    (@msaari)

    That setting is indeed only for backend use. Is your front end search a some kind of AJAX search? AJAX is always an admin process, even if the search happens in the front end, so that would explain it. It’s still not right, though.

    Based on your problems here, I’m guessing there’s something funny about your front-end search.

    Thread Starter pickme

    (@pickme)

    Hi @msaari

    Indeed, frontend search results are provided with AJAX.
    In that case, am I supposed to tick ‘Admin search : Use Relevanssi for admin searches’ even if I don’t utilise WP admin search? (I do though).

    Thanks

    Plugin Author Mikko Saari

    (@msaari)

    Yes, looks like you need to have. Whether it’s necessary or not depends on the way the search is done.

    Thread Starter pickme

    (@pickme)

    Thank you for your support @msaari !

    Regards

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘WP / Woocommerce admin search’ is closed to new replies.