wp query - Extend product search with meta in WooCommerce

admin2025-06-05  4

I would improve the search bar in order to exploit manufacture attribute linked to product.

I try to use this to filter product by a custom meta (no product attribute)

function custom_search_query( $query ) {
     if ( !is_admin() && $query->is_search ) {
          $query->set('meta_query', array(
               array(
                    'key' => 'manufacture',
                    'value' => $query->query_vars['s'],
                    'compare' => 'LIKE'
               )
          ));
     };
}
add_filter( 'pre_get_posts', 'custom_search_query');

But this puts this condition in AND with standard query, I need to put it in OR.

Any suggestions?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749075942a316149.html

最新回复(0)