Support

Account

Home Forums General Issues Meta query if checkbox false?

Solved

Meta query if checkbox false?

  • I can list checked posts with

    $args = array(
            'numberposts' => -1,
            'post_type' => 'team',
            'meta_query' => array(
              array(
                'key'   => 'is_manager',
                'value' =>  true,
                'compare' => 'IN'
              )
            )
          );

    How I can list unchecked posts?I want something like this

    $args = array(
            'numberposts' => -1,
            'post_type' => 'team',
            'meta_query' => array(
              array(
                'key'   => 'is_manager',
                'value' =>  false,
                'compare' => 'IN'
              )
            )
          );

    But this don’t work. what wrong?

  • What field type?

    Do you mean a true/false field?

  • yes, true/false field

  • posts with this field checked

  • 
    // checked
    $args = array(
            'numberposts' => -1,
            'post_type' => 'team',
            'meta_query' => array(
              array(
                'key'   => 'is_manager',
                'value' =>  1,
                'compare' => '='
              )
            )
          );
    // not checked
    $args = array(
            'numberposts' => -1,
            'post_type' => 'team',
            'meta_query' => array(
              array(
                'key'   => 'is_manager',
                'value' =>  0,
                'compare' => '='
              )
            )
          );
    
  • for some reason i need check and uncheck posts to this works

  • 
    // for set to false of no value
    $args = array(
            'numberposts' => -1,
            'post_type' => 'team',
            'meta_query' => array(
              'relation' => 'OR',
              array(
                'key'   => 'is_manager',
                'value' =>  0,
                'compare' => '='
              ),
              array(
                'key'   => 'is_manager',
                'compare' => 'NOT EXISTS'
              )
            )
          );
    
Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.