0
votes

I've created a Field group called 'Team Members' and set the field type as repeatable with three sub fields; Image, Position and Name.

The rule for this group is to show within a custom widget I've created. When I drag the widget in the Appearance > Widgets area of WordPress I can see it is indeed there and can add members / images to my widget.

Where I've hit a brick wall is trying to output this data on the front end through my widget template.

This is my code:

   <?php if( have_rows('team_members') ): ?>

            <ul class="slides">

            <?php while( have_rows('team_members') ): the_row(); 

              // vars
              $image = get_sub_field('image');
              $content = get_sub_field('name');
              $link = get_sub_field('position');

              ?>

              <li class="slide">

                <?php if( $link ): ?>
                  <a href="<?php echo $link; ?>">
                <?php endif; ?>

                  <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />

                <?php if( $link ): ?>
                  </a>
                <?php endif; ?>

                  <?php echo $content; ?>

              </li>

            <?php endwhile; ?>

            </ul>

          <?php endif; ?>

Where am I going wrong?

1

1 Answers

1
votes

To get values from your custom widget via ACF the syntax is:

if ( have_rows( 'team_members', 'widget_' . $widget_id ) ) :
    while have_rows( 'team_members', 'widget_' . $widget_id ) ) : the_row();

        // get sub fields ...

    endwhile;
endif;