
timwakeling(@timwakeling)
7 Posts
Customers
Quote from timwakeling on June 29, 2023, 12:18
I see that HUSKY allows me to add filters for custom meta.
That's good, but I want to search by custom meta, not filter. So I have custom meta for each product, _manufacturer_part_number, and I want this to be included in the fields which are searched. But I don't want the customer to filter by this.
Can it be done?
Thanks
I see that HUSKY allows me to add filters for custom meta.
That's good, but I want to search by custom meta, not filter. So I have custom meta for each product, _manufacturer_part_number, and I want this to be included in the fields which are searched. But I don't want the customer to filter by this.
Can it be done?
Thanks

Pablo Borysenco(@pavlo_borysenco)
34,196 Posts
Quote from Pablo Borysenco on June 30, 2023, 11:18
Hello
You want to have text search on meta fields, please add your meta key here - https://share.pluginus.net/image/i20230630121848.png
Hello
You want to have text search on meta fields, please add your meta key here - https://share.pluginus.net/image/i20230630121848.png

timwakeling(@timwakeling)
7 PostsTopic Author
Customers
Quote from timwakeling on June 30, 2023, 13:12
Thank you - that works, but what I really wanted was for the meta fields to be included in the initial search, the one from the main search box.
I have code like this to make queries in general include custom meta, which works well when your plugin is not enabled, but seems to cause an infinite loop when used with your plugin. Any idea why?
add_filter( 'posts_join', 'cf_search_join' );
add_filter( 'posts_where', 'cf_search_where' );
add_filter( 'posts_distinct', 'cf_search_distinct' );
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .= ' LEFT JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
function cf_search_where( $where ) {
global $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;
}
function cf_search_distinct( $where ) {
global $wpdb;
if ( is_search() ) {
return 'DISTINCT';
}
return $where;
}
Thank you - that works, but what I really wanted was for the meta fields to be included in the initial search, the one from the main search box.
I have code like this to make queries in general include custom meta, which works well when your plugin is not enabled, but seems to cause an infinite loop when used with your plugin. Any idea why?
add_filter( 'posts_join', 'cf_search_join' );
add_filter( 'posts_where', 'cf_search_where' );
add_filter( 'posts_distinct', 'cf_search_distinct' );
function cf_search_join( $join ) {
global $wpdb;
if ( is_search() ) {
$join .= ' LEFT JOIN ' . $wpdb->postmeta . ' ON ' . $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
}
function cf_search_where( $where ) {
global $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;
}
function cf_search_distinct( $where ) {
global $wpdb;
if ( is_search() ) {
return 'DISTINCT';
}
return $where;
}

Pablo Borysenco(@pavlo_borysenco)
34,196 Posts
Quote from Pablo Borysenco on July 3, 2023, 10:15
Hello
yes of course your custom code will cause a conflict
if there is already a search query for my plugin, then the metadata table is already connected(joined).
The regex part of the code will always change my plugin's text search
Please read this - https://products-filter.com/manipulate-search-data-options
Hello
yes of course your custom code will cause a conflict
if there is already a search query for my plugin, then the metadata table is already connected(joined).
The regex part of the code will always change my plugin's text search
Please read this - https://products-filter.com/manipulate-search-data-options

timwakeling(@timwakeling)
7 PostsTopic Author
Customers
Quote from timwakeling on July 5, 2023, 15:37
Thank you very much for this - just what I need to know. I will be working on this project tomorrow and hopefully will be able to use this knowledge to solve my problem. :)
Thank you very much for this - just what I need to know. I will be working on this project tomorrow and hopefully will be able to use this knowledge to solve my problem. :)

Pablo Borysenco(@pavlo_borysenco)
34,196 Posts
Quote from Pablo Borysenco on July 6, 2023, 11:26
Hello
Ok! Welcome;)
Hello
Ok! Welcome;)