3

I was looking on another question , and thought of changing the original query to compare two meta_key values.

This question deals with finding WC coupons that reached their usage limit. There are two values stored as post meta data: usage_limit and usage_count.

I want to find all the coupons that the usage_count is equal or greater than the usage_limit. Something like:

$args = array(
    'posts_per_page' => -1,
    'post_type'      => 'shop_coupon',
    'post_status'    => 'publish',
    'meta_query'     => array(
        array(
            'key'     => 'usage_count',
            'value'   => [meta_key='usage_limit'] value here,
            'compare' => '>='
        )
    )
);

I didn't find any solution for this type of query, but thought there might be an elegant way.

Krupal Panchal
  • 1,553
  • 2
  • 13
  • 26
Shir Gans
  • 1,976
  • 3
  • 23
  • 40
  • That is not possible using this syntax. `value` is supposed to be an actual data value, you can not substitute that for another meta key name at this point. – 04FS Oct 04 '19 at 11:12

0 Answers0