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

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 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.

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

Hello

You want to have text search on meta fields, please  add  your  meta key  here - https://share.pluginus.net/image/i20230630121848.png

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

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

 

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. :)

Hello

Ok! Welcome;)