Home › Forums › General Issues › True/False trigger on frontend › Reply To: True/False trigger on frontend
This code got what I needed. Make sure to add the #hide_this_div to the whatever you want to hide and change the ‘ACF-field-name’ in this code to your field name. You can change the ‘post’ to any CPT.
add_action('template_redirect', 'hide_disabled_blocks');
function hide_disabled_blocks() {
global $post;
// get dynamic project id
$post_id = $post->ID;
// get value of true-false field in each post
$hidediv = get_post_meta($post_id, 'ACF-field-name', true);
if is_singular( 'post' ) :?>
<style type="text/css">
<?php
// if "ACF true-false command" is false, hide the Div ID
if ( ($hidediv == '0') || (empty($hidediv)) ): ?>
#hide_this_div { display: none; }
<?php endif;
?>
</style>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.