Support

Account

Home Forums General Issues Hiding custom fields using conditional logic? Reply To: Hiding custom fields using conditional logic?

  • Thank you very much James. With your help I figured it out. 😀

    I created a True/False field and called it “view_profile”, and added this block of code into my array in the acf.php file:

    array (
         'key' => 'field_57467a65db91f',
          'label' => 'View Profile',
          'name' => 'view_profile',
          'type' => 'true_false',
          'message' => 'Show biography?',
          'default_value' => 0,
    ),

    This displays the checkbox option in the backend.

    Finally, I used conditional statements to determine if a user wants to link a profile or not in my archive-employee.php.

    <div class="entry-content">
    
        <?php
    
        while($employee->have_posts())
        {
            $employee->the_post();
            ?>
    		<div class="team-roster">
    		<?php if ( get_field( 'view_profile' ) ): ?>
    			  <a href="<?php echo get_permalink($id); ?>">
                    <div class="title"><?php echo get_field('name', $id); ?></div>
    				<div class="subtitle"><?php echo get_field('job_title', $id); ?></div>	
    				<div class="button">View Profile</div>
    			  </a>
    			
    			<?php else : ?>	
    			<a href="#">
                    <div class="title"><?php echo get_field('name', $id); ?></div>
    				<div class="subtitle"><?php echo get_field('job_title', $id); ?></div>	
    			</a>
    							
    				<?php endif; ?>
                    <img src="<?php echo get_field('employee_featured_image', $id); ?>" alt="<?php echo the_title(); ?>" />
    				<img src="<?php echo get_field('employee_featured_image_hover' ,$id); ?>" alt="<?php echo the_title(); ?>"  />
            </div>
            <?php
        }
    
        ?>
    </div>

    Awesome!