Support

Account

Home Forums Add-ons Repeater Field Link in Repeater won’t work

Helping

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; ?>
    &nbsp; | &nbsp;
    <?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()?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.