Support

Account

Home Forums Add-ons Repeater Field Repeater not display in front end

Solving

Repeater not display in front end

  • Hey there, I’m trying to display a repeater on my page but for the life of me, I cannot get the fields to display in the front end.

    It is outside the loop. I’ve followed tutorial after tutorial, but cannot get the fields to display. Could you help me please?

    <div class="stats allignfull">
        <div class="wp-block-columns has-6-columns">
    
    <?php 
    global $post;    
        
        if( have_rows('stat_repeater', $post->ID) ):
            while( have_rows('stat_repeater', $post->ID) ): the_row(); 
    
            // vars
            //$image = the_sub_field('stat_image');
            //$headline = the_sub_field('stat_headline');
            //$stat_text = the_sub_field('stat_text');
    
        ?>
    
    <div class="wp-block-column">
                <div class="wp-block-classic align">
    
                <p> <?php $image = get_sub_field('stat_image');
    $size = 'full'; // (thumbnail, medium, large, full or custom size)
    if( $image ) {
        echo wp_get_attachment_image( $image, $size );
    }?></p>
           
            <p class="headline">
                <span class="font-color-blue-dark"><strong><?php echo get_sub_field('stat_headline'); ?></strong></span>
            </p>
            <p class="center-text"><?php echo get_sub_field('stat_text'); ?></p>
     </div>
             </div>
    
    <?php endwhile;
    
    else :
    
    // no rows found
    
     endif; ?>
    
        </div>	
    </div>
  • Hey Jon,

    Just to rule out a couple of things, you say this is outside of the loop so is it not between the following lines?

    
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
      <?php // The code is not here? ?>
    <?php endwhile; ?>
    

    Also, is the repeater located on the page you’re trying to display it on? Or is it elsewhere?

    Cheers, Dan

  • Hey Jon,

    All seems fine. I did notice you’re using the ID return method for your image. The setting defaults to an array return so I’ve modified my answer to suit.

    I’ve tidied up your code and tested both in and out of the loop within a page template and it works perfectly.

    
    <div class="stats allignfull">
        <div class="wp-block-columns has-6-columns">
            <?php if( have_rows('stat_repeater') ): ?>
                <?php while( have_rows('stat_repeater') ): the_row(); ?>
                    <div class="wp-block-column">
                        <div class="wp-block-classic align">
                            <?php
                            $image = get_sub_field('stat_image');
                            if( $image ) {
                                $url = $image['url']; ?>
                                <p><img src="<?php echo esc_url($url); ?>" alt="<?php the_sub_field('stat_headline'); ?>" /></p>
                            <?php } ?>
                            <p class="headline">
                                <span class="font-color-blue-dark"><strong><?php the_sub_field('stat_headline'); ?></strong></span>
                            </p>
                            <p class="center-text"><?php the_sub_field('stat_text'); ?></p>
                        </div>
                    </div>
                <?php endwhile; ?>
            <?php endif; ?>
        </div>
    </div>
    

    The only reason I could see this not working is if you’re trying to get data from a different page. If this is the case you’d need to include the ID that is the source of the data in the initial query so, it’d be something like this:

    
    <?php
    $page = get_page_by_title( 'About' );
    $about_page_id = $page->ID;
    ?>
    
    <?php if( have_rows('stat_repeater', $about_page_id) ): ?>
        <?php while( have_rows('stat_repeater', $about_page_id) ): the_row(); ?>
    

    I hope this helps!

  • Hey guys, Solved the problem.

    Dan’s question about the repeater being on this page or somewhere else made things click. The repeater is actually on the options page, so reading that documentation helped figure out what was wrong.

    I would suggest putting a options page example on the repeater documentation, to help others that hit the same problem.

    Cheers for the help guys!

    <div class="stats allignfull">
        <div class="wp-block-columns has-6-columns">
    
    <?php 
        
        if( have_rows('stat_repeater', 'option') ):
            while( have_rows('stat_repeater', 'option') ): the_row(); 
        ?>
    
    <div class="wp-block-column">
                <div class="wp-block-classic align">
    
                <p> 
    <?php $image = get_sub_field('stat_image', 'option');
    $size = 'thumbnail'; // (thumbnail, medium, large, full or custom size)
    if( $image ) {
        echo wp_get_attachment_image( $image, $size );
    }?></p>
           
            <p class="headline">
                <span class="font-color-blue-dark"><strong><?php echo get_sub_field('stat_headline'); ?></strong></span>
            </p>
            <p class="center-text"><?php echo get_sub_field('stat_text'); ?></p>
     </div>
             </div>
    
    <?php endwhile;
    
    else :?>
    
    no rows found
    <?php
     endif; ?>
    
        </div>	
    </div>
    
  • This reply has been marked as private.
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.