Search code examples
wordpressadvanced-custom-fieldsacfpro

Show post if true/false is no ACF


How to display only posts, what have field "nezobrazovat" as false?

This is my code:

        $args = array(
            'posts_per_page' => 3,
            'post_type' => 'mycustompost',
            'key'=> 'nezobrazovat',
            'value'=>'no',
        );

This doesnt work, all first 3 posts are displayed


Solution

  • From the acf docs the value is 1 or 0

    $posts = get_posts( array(
        'meta_query' => array(
            array(
                'key'   => 'show_in_sidebar',
                'value' => '1',
            )
        )
    ) );
    

    https://www.advancedcustomfields.com/resources/true-false/