customization - Querying posts that don't have a certain key value or don't have the key

admin2025-04-18  1

The intention is to search for customers who do not have coupon X or do not have any coupon.

    $query = array (
        'post_type'      => 'clients',
        'meta_query'=> array(
            'relation' => 'OR',
            array(
               'key' => 'cupom',
               'value' => $idCupom,
               'compare' => '!=',
        ), array(
              'key' => 'cupom',
              'compare' => 'NOT EXISTS',
              'value' => '',
        )),
        'posts_per_page' => -1,
    );

I am doing according to other answers I found on the web, but the query returns wrong when it finds a post that has a meta_value different from the one searched.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744971121a277492.html

最新回复(0)