Support

Account

Home Forums ACF PRO Once checked, always true

Solved

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(
    		       array(
    		           'key' 		=>	'featured-home',
    		       )
    		    )
    		);
    	?>
    	<?php $loop = new WP_Query( $args ); ?>
    <div>
    	<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
      <div>
       <h2><?php the_field('pagetitle'); ?></h2>
        <h3><?php the_field('subtitle'); ?></h3>
           <p class="readMore">
              <a href="<?php the_permalink(); ?>">Read more</a>
           </p>
      </div>
    	<?php endwhile; ?>
    </div>
    	<?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(
                      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)

The topic ‘Once checked, always true’ is closed to new replies.