Home Forums General Issues If True do this / False do that Reply To: If True do this / False do that

  • Try this code. Make sure to add the #hide_this_div to the whatever you want to hide:

    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">
    		// if "ACF true-false command" is false, hide the Div ID
    		if  ( ($hidediv == '0') || (empty($hidediv)) ): ?>
    			#hide_this_div { display: none; }
    		<?php endif;