Reputation: 3224
I'm trying to exclude results with the name cable
from the WP_Query. I have attempted so far but no luck.
Here is my query. Products that have the word cable
should be excluded.
$args = array( 'post_type' => 'product', 'per_page' => '40', 'posts_per_page' => '24','product_cat'=>'garden-lighting','meta_key' => 'total_sales','orderby' => 'meta_value_num','meta_query' => array(
array(
'key' => 'Product Name',
'value' => 'cable',
'compare' => 'NOT LIKE'
)
));
$args['meta_query'] = $woocommerce->query->get_meta_query();
$loop = new WP_Query( $args );
How do i solve this?
Upvotes: 0
Views: 936
Reputation: 19308
The 'meta_query' item you add to the array on the first line is immediately overwritten on the second line with:
$args['meta_query'] = $woocommerce->query->get_meta_query();
Append your custom query after you've set the WC version.
Example:
// Set WC meta query.
$args['meta_query'] = $woocommerce->query->get_meta_query();
// Append custom query array.
$args['meta_query'][] = array(
'key' => 'Product Name',
'value' => 'cable',
'compare' => 'NOT LIKE',
);
Upvotes: 1