Home › Forums › Add-ons › Repeater Field › Link in Repeater won’t work
I added a repeater and all of the fields are working except the link field won’t show. When I add get_sub_field to get_field it breaks the site.
<?php $link = get_field('floor_plan_link');
if( $link ):
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
?>
Here’s the full code –
<ul>
<?php
// check if the repeater field has rows of data
if( have_rows('floorplans') ):
// loop through the rows of data
while ( have_rows('floorplans') ) : the_row();
// display a sub field value
?>
<li>
<?php if( get_sub_field('floor_plan_title') ): ?>
<?php the_sub_field('floor_plan_title'); ?>
<?php endif; ?>
<?php if( get_sub_field('bedrooms') ): ?>
<?php the_sub_field('bedrooms'); ?>
<?php endif; ?>
|
<?php if( get_sub_field('bathrooms') ): ?>
<?php the_sub_field('bathrooms'); ?>
<?php endif; ?>
<?php $image = get_sub_field('floor_plan_image');
if( !empty( $image ) ): ?>
<img />" alt="<?php echo esc_attr($image['alt']); ?>" />
<?php endif; ?>
<?php if( get_sub_field('square_foot') ): ?>
<?php the_sub_field('square_foot'); ?>
<?php endif; ?>sq. ft.
<?php $link = get_field('floor_plan_link');
if( $link ):
$link_url = $link['url'];
$link_title = $link['title'];
$link_target = $link['target'] ? $link['target'] : '_self';
?>
<a>" target="<?php echo esc_attr( $link_target ); ?>">
<?php if( get_sub_field('floorplans_link_text') ): ?>
<?php the_sub_field('floorplans_link_text'); ?>
<?php endif; ?></a>
<?php endif; ?>
</li>
<?php
endwhile;
else :
// no rows found
endif;
?>
</ul>
I appreciate any help!!

why are you using get_field() for the subfield instead of get_sub_field()?
You must be logged in to reply to this topic.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.