I have 2 buttons for volunteer and register. I’d like them to not appear on the front end if they are left empty on the backend. This is my code:
` <div class=”CTA”>
<?php if( have_rows(‘cta_buttons’) ): ?>
<?php
while ( have_rows( ‘cta_buttons’ ) ): the_row();
// Get sub field values.
$link = get_sub_field( ‘register’ );
?>
<button>
target=”_blank”> Register
</button>
<?php endwhile; ?>
<?php endif; ?>
<?php if( have_rows(‘cta_buttons’) ): ?>
<?php
while ( have_rows( ‘cta_buttons’ ) ): the_row();
// Get sub field values.
$link = get_sub_field( ‘volunteer’ );
?>
<button>
target=”_blank”> Volunteer
</button>
<?php endwhile; ?>
<?php endif; ?>
</div>
‘
If I’m understanding correctly, you’ll need this:
<?php
$volunteer = get_sub_field( 'volunteer' );
$register = get_sub_field( 'register' );
?>
<?php if($volunteer): ?><button>Volunteer button</button><?endif;?>
<?php if($register): ?><button>Register button</button><?endif;?>