Support

Account

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>