Meta Query Filter in WooCommerce

Home / Uncategorized / Meta Query Filter in WooCommerce

Question:
I want to filter my products with custom post meta key ("_city_name") as well as the keyword ("s") with AND operation currently I’m doing in my functions.php:function my_modify_main_query( $query ) {

$meta_query_args = array(
‘meta_query’ => array(
array(
‘key’ => ‘_city_name’,
‘value’ => ‘new york’,
‘compare’ => ‘LIKE’,
)
)
);
$query->set(‘meta_query’, $meta_query_args);
}

add_filter( ‘pre_get_posts’, ‘my_modify_main_query’ );
It’s working if I don’t add keyword in the GET params ("s"), but if I add keyword it stop working ("s=beer&city=newyork")…?


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *