what im trying to do is to make a query to get all the lastest new products, Im using woocommerce Plugin.
newest products are products that been created in the last 30 days.
i have tried to get this by meta_query, but could not find the right key, or maybe it is the worng way.
$args = array(
'post_type' => 'product',
'posts_per_page' => 7,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $terms,
'operator' => 'IN'
)),
'meta_query' => array(
array( // Simple products type
'key' => '[ tried a key like '_sale_price' which give you products onsale]',
'value' => 0,
'compare' => '>',
'type' => 'numeric'
),
),
);
$loop = new WP_Query( $args );
any suggestion please?
2
Answers
Thanks a lot Alexandr i needed it dynamic so i changed it a bit, this way the date is updated all the time, and its works :)
this way im getting the latest new products in the past 1 mount
I think you should not use ‘meta query’ because the product create date contains in the ‘post’ table not in the ‘post meta’. You have to try use ‘date_query’. Something like this: