Check for not NULL not working in meta query

enter image description here

My code:

    if ($sri) {
      $sri   = intval($sri);
      $args  = [
          'post_type'   => 'notification',
          'numberposts' => -1,
          'meta_query'  => [
              'relation' => 'AND',
              [
                  'key'     => 'send_at',
                  'value'   => Ut::getMysqlTimestamp('now'),
                  'compare' => '<=',
              ],
              //            array(
              //                'key'     => 'was_sent',
              //                'value'   => '1',
              //                'compare' => '=',
              //            ),
              [
                  'key'     => 'related_post_id',
                  'value'   => $sri,
                  'compare' => '='
              ],
              [
                  'key'     => 'notification_type',
                  'value'   => Notification::STORY_REQUEST_MAIN_TYPE,
                  'compare' => '='
              ],
//              [
//                  'relation' => 'OR',
//                  [
//                      'key'     => 'related_post_id2',
//                      'value' => '',
//                      'compare' => 'NOT EXISTS',
//                  ],
//                  [
//                      'key'     => 'related_post_id2',
//                      'value'   => '',
//                      'compare' => '='
//                  ],
//                 [
//                      'key'     => 'related_post_id2',
//                      'value'   => null,
//                      'compare' => '='
//
//                  ],
//                  [
//                      'key'     => 'related_post_id2',
//                      'value'   => 'NULL',
//                      'compare' => '='
//
//                  ]
//              ]
          ],
          'meta_key'    => 'send_at',
          'orderby'     => 'meta_value',
          'order'       => 'DESC'
      ];
      $posts = get_posts($args);
      d($posts);
      die('bb');

the commented out part of the code doesn’t work

even though the value is clearly NULL

WordPress is of 2020 so not old… version 5.3

Read more here:: Check for not NULL not working in meta query

Leave a Reply

Your email address will not be published. Required fields are marked *