Include custom meta in searches
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 pleaseIf 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.
Quote from timwakeling on June 29, 2023, 12:18I 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
Quote from Pablo Borysenco on June 30, 2023, 11:18Hello
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
Quote from timwakeling on June 30, 2023, 13:12Thank 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?
function cf_search_where( $where ) {
Quote from Pablo Borysenco on July 3, 2023, 10:15Hello
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
Quote from timwakeling on July 5, 2023, 15:37Thank 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. :)
Quote from Pablo Borysenco on July 6, 2023, 11:26Hello
Ok! Welcome;)
Hello
Ok! Welcome;)