Support

Account

Home Forums General Issues True/False trigger on frontend

Solving

True/False trigger on frontend

  • Hello,

    I’d like to have the True/False toggle that is in the WP edit page to Show/Hide a div on the frontend. I can’t seem to find any answers to do this anywhere.

    Any help would be greatly appreciated

  • This is something that you need to code.

    
    if (get_field('your-tru-false-field-name)) {
      // show the div
    }
    
  • 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>
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.