I have a code that it deletes the products marked as expired, and I now want to adapt a new product order system, but I am not able to know the correct order of the wordpress meta_query. currently my code is as follows:
$args = array(
'post_type' => 'coupons',
'posts_per_page' => $mts_options['mts_tab_postsnum'],
'meta_query' => array(
'exists' => array (
'key' => 'mts_coupon_premium',
'compare' => 'EXISTS',
),
'relation' => 'OR',
'not_exists' => array (
array (
'key' => 'mts_coupon_premium',
'compare' => 'NOT EXISTS',
),
array (
'key' => 'mts_coupon_expired',
'compare' => 'NOT EXISTS',
),
),
),
'orderby' => 'exists not_exists date',
'order' => 'DESC',
'no_found_rows' => true,
);
if ( 'latest' === $cat ) {
$terms = new stdClass();
$terms->term_id = 'latest';
} else {
$terms = get_term( $cat );
$args['tax_query'] = array(
array(
'taxonomy' => 'mts_coupon_categories',
'terms' => $terms->term_id,
)
);
}
$tabposts = new WP_Query($args);
At this moment I managed to exclude the mts_coupon_expired products from the " not_exists " array listing but whenever I try to do the same in " exists " it crashes the listing.
the logic would be List the existing and non-existing mts_coupon_premium meta key and delete these two meta key
'key' => 'mts_coupon_expired',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'mts_coupon_expired',
'value' => '0',
'type' => 'numeric'
)
Can anyone save my day? Thanks