admin管理员组

文章数量:1130349

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?

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?

本文标签: wp queryExtend product search with meta in WooCommerce