Home Forums ACF PRO Relationship Repeater not working per docs example


Relationship Repeater not working per docs example

  • I have repeater field in options containing relationships to page objects as “featured pages” for the purpose of “lead ins” on the home page. I’ve tried to follow the example of Basic loop (with setup_postdata) as closely as possible but it is still not displaying the data. echoing the posts object shows that the data has been retrieved properly, just not displayed. Strangely, the call to the_field(‘first_read’) shows the data from a field of the same name on the home page (outer loop), not the related pages (inner loop) as desired, which tells me that setup_postdata($post) may not be doing its job. Here is the code, hope you can help.

    Template Name: Front Page
    get_header(); ?>
    <?php /* Start loop */ ?>
    <?php while (have_posts()) : the_post(); ?>
        <main id="main" class="body-content row column" role="main">
            <?php get_template_part('template-parts/breadcrumbs'); ?>
            <div class="medium-8 columns">
                <div class="row">
                    <section id="featured " class="show-for-medium">
                        <?php echo do_shortcode('[foogallery id="2942"]'); ?>
                    <div class="uvp">
                        <h1 class="hide">The Blah Blah</h1>
                        <h2 class="subheader">More Blay Blah</h2>
                        <div class="first-read callout-first-read">
                            <?php the_field('first_read'); ?>
                    $posts = get_field('home_featured_sections_2', 'option');
                    echo "<pre>";
                    echo print_r( $posts );
                    echo "</pre>";
                    //The print_r shows the proper data is being retrieved
                    if( $posts ): ?>
                    <section class="row column small-up-1 medium-up-2">
                        <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
                            <?php setup_postdata($post); ?>
                            <div class="column media-object stacked">
                                <div class="media-object-section">
                                    <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                                    <div class="thumbnail">
                                        <a href="<?php the_permalink(); ?>" ><img src="<?php the_post_thumbnail(); ?>"></a>
                                <div class="media-object-section">
                                    <p><?php the_field('first_read'); ?></p>
                                    <!-- The above field repeatedly outputs the first_read from the home page rather then the inner loop first_reads as expected, plus no other inner loop data is output -->
                        <?php endforeach; ?>
                        <?php wp_reset_postdata(); ?>
                    <?php endif; ?>
            <?php get_sidebar(); ?>
    <!--        </div>-->
            <!-- News -->
        <!-- End Content -->
    <?php endwhile; ?>
    <?php get_footer(); ?>
  • Resolved.

    It turns out that the $posts = get_field(‘home_featured_sections_2’, ‘option’); was not referring to the actual relationships field, but to the parent of the relationships field. I put a have_row loop around it the code worked properly….with a few minor other tweaks.

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

The topic ‘Relationship Repeater not working per docs example’ is closed to new replies.