Home Forums ACF PRO Once checked, always true


Once checked, always true

  • I have an acf true/false that shows content on the homepage if you check it. It works fine. But, if you uncheck it, the content will not be removed from the homepage, it stays visible.

    How do I adjust this part of code to make sure that the true option will be undone after unchecking the true/fasle checkbox?

     $args =         array(													
    		'post_type' => 'product', 
    		'posts_per_page' => -1, 
    		'orderby' => 'title', 
    		'order' => 'ASC',
    		'meta_query' => array(
    		           'key' 		=>	'featured-home',
    	<?php $loop = new WP_Query( $args ); ?>
    	<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
       <h2><?php the_field('pagetitle'); ?></h2>
        <h3><?php the_field('subtitle'); ?></h3>
           <p class="readMore">
              <a href="<?php the_permalink(); ?>">Read more</a>
    	<?php endwhile; ?>
    	<?php wp_reset_query(); ?>
  • A true/false field saves either a 1 or 0. Add the value you want to select by to your meta_query argument. It would probably also be a good idea to set the type to numeric.

    'meta_query' => array(
                        'key'   => 'featured-home',
                        'value' => 1,
                        'type'  => 'numeric',
  • Hube2, Thank you very much, it works like a charm!!

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

You must be logged in to reply to this topic.