PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Custom search broken after update

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi,

I have some custom code which runs when a user perform a text search from the default woocommerce product searchbox, which includes custom fields in the search performed (so for example it allows to search by sku).

The code is the following:

 

/**
* Join posts and postmeta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
function cf_search_join( $join ) {
global $wpdb;

if ( is_search() ) {
$join .=' LEFT JOIN '.$wpdb->postmeta. ' cfmeta ON '. $wpdb->posts . '.ID = cfmeta.post_id ';
// $join .=" LEFT JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id";
}
return $join;
}
add_filter('posts_join', 'cf_search_join' );

/**
* Modify the search query with posts_where
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where
*/
function cf_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 (cfmeta.meta_value LIKE $1)", $where );
}

return $where;
}
add_filter( 'posts_where', 'cf_search_where' );

/**
* Prevent duplicates
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_distinct
*/
function cf_search_distinct( $where ) {
global $wpdb;

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

return $where;
}
add_filter( 'posts_distinct', 'cf_search_distinct' );

But with the last update in husky the code doesn't work anymore. It works if I disable the husky plugin.

Any advice?

thanks :-)

Hello

Please  try to  use  husky text  search - https://products-filter.com/shortcode/woof_text_filter

Thanks! I'll try it out and let you know

hello

Ok! Welcome;)

Hi, it seems to be working :-)

Is there a filter / hook which can be used to customize the output of the text input? (I need to add a tooltip with some help text)

 

Thanks!

Hello

Unfortunately the plugin does not have such a feature, you should customize the plugin code -  \wp-content\plugins\woocommerce-products-filter\ext\by_text\views\shortcodes\woof_text_filter.php

Hi Pablo,

I have tested the solution thoroughly , and I've come across a problem.

 

This is my shortcode: [woof_text_filter taxonomy_compatibility="1" sku_compatibility="1" custom_fields="1"]

In"meta section" of the plugin options I've added 3 custom fields which I want to filter for (model_brand, _sku and references), all are configured for"text search" and as"string" value.

Unfortunately, only the sku search seems to be working :-/

 

Any advice?

 

Thanks!

 

Hello

Please  read this - https://share.pluginus.net/image/i20231121131851.png

try this shortcode - [woof_text_filter taxonomy_compatibility="1" sku_compatibility="1" custom_fields="model_brand,references"]

Thank you :-)

Ok it's working, just one more question: if I hit return while searching, I get redirected on the shop page with this URL"?swoof=1&woof_text=bruna&paged=1", but even if the search has results, they are not shown here

Hello

Please  drop me exact  link  to the  issue

Hi Pablo,

I'm currently testing it in my local enviroment. I'll ask the clienti if it's ok to go online like this so that you can check it out

OK!  I will wait for your answer