Support

Account

Home Forums ACF PRO True/False – No Value for False Reply To: True/False – No Value for False

  • I had multiple things going on but in the end this was the code that worked for me. Feel free to dissect out of this what you need. In my case the client wanted the featured projects to be at the top and then added the criteria that they would also like to exclude some posts from displaying in the list but still wanted them accessible as single posts. With this my featured posts were at the top and my excluded posts did not display. And if a user clicked both boxes it defaulted to not display.

                        'post_type'         => 'work',
                        'post_status'       => 'publish',
                        'posts_per_page'    => -1,
                        'meta_key'          => 'featured_project',
                        'orderby'           => 'meta_value date',
                        'order'             => 'DSC',
                        'meta_query'        => array(
                            'relation' => 'OR',
                            'exclude_posts' => array(
                                'relation' => 'OR',
                                array(
                                    'key'       => 'exclude_project',
                                    'compare'   => '!=',
                                    'value'     => '1'
                                ),
                                array(
                                    'key'       => 'exclude_project',
                                    'type'      => 'BOOLEAN',
                                    'value'     => false
                                ),
                                array(
                                    'key'       => 'exclude_project',
                                    'compare'   => 'NOT EXISTS'
                                ),
                            ),
                            'featured_posts' => array(
                                'relation'  => 'AND',
                                array(
                                    'key'       => 'featured_project',
                                    'value'     => '1',
                                    'compare'   => '='
                                ),
                                array(
                                    'key'       => 'exclude_project',
                                    'compare'   => '!=',
                                    'value'     => '1'
                                ),
                            ),
                        ),
                        
                    );