Support

Account

Home Forums General Issues Checkbox meta_query with 0 value

Solving

Checkbox meta_query with 0 value

  • I got a problem with value = 0 for meta_query checkbox field:

    $args = [
    	                'post_type'        => 'post',
    	                'post_status'      => 'publish',
    	                'posts_per_page'   => - 1,
    	                'meta_query' => array(
    		                array(
    			                'key'     => 'test_field',
    			                'value'   => 0,
    			                'compare' => 'LIKE',
    		                ),
    	                ),
                    ];

    This code works fine if value is 1,2,3 etc. But when I set meta_query value to 0 i get all posts which has not empty test_field in post.

    How can i got only posts with value = 0 ?
    i have tried change compare to IN or = but its not words for checkbox fields

  • EDIT:
    It works wrong if value is 0 or 1, for other numeric values its fine

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Checkbox meta_query with 0 value’ is closed to new replies.