最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论