Support

Account

Home Forums General Issues WP_Query to exclude posts by multiple meta keys Reply To: WP_Query to exclude posts by multiple meta keys

  • The reason is OR

    If alumi == 1 and intern_dev == 0 then one OR the other == 0 and will be returned.

    You need to use nested queries

    
    'meta_query' => array(
      'relation' => 'AND',
      array(
        'relation' => 'OR',
        array(
          'key' => 'alumni',
          'value'      => '0',
          'compare'   => '==',
        ),
        array(
          'key' => 'alumni',
          'compare' => 'NOT EXISTS',
        )
      ),
      array(
        'relation' => 'OR',
        array(
          'key' => 'intern_dev',
          'value'      => '0',
          'compare'   => '==',
        ),
        array(
          'key' => 'intern_dev',
          'compare' => 'NOT EXISTS',
        )
      )
    ),