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!
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.