WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
[resolved] repeater field working on one page but not others (2 posts)

  1. bshuchter
    Member
    Posted 1 year ago #

    Strange problem I'm having. I have one template with a repeater field on it, and several pages which use that one template. But only one of the pages shows the content of the repeater field - the others are blank. Even if I try to "force" the repeater field to see the content of one of the other pages, it's still blank. The code I'm using in the template is very simple:

    if (get_field('photos')) {
    	echo '<div id="photo-gallery">';
    	while (has_sub_field('photo'))
    	{
    		echo '<img class="alignleft size-thumbnail" src="';
    		echo get_sub_field('photo');
    		echo '" />';
    	}
    	echo '</div>';
    }

    On one of the pages, this code displays all the photos uploaded to the repeater field, as expected. On every other page using the same template, it displays nothing (but does echo the div tag).

    I upgraded ACF to 3.5.4 in the middle of developing this site, so not sure if that caused the problem.

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  2. bshuchter
    Member
    Posted 1 year ago #

    I managed to fix this problem by using a different loop, namely:

    $rows = get_field('photos');
    if ($rows) {
    	echo '<div id="photo-gallery">';
    	foreach ($rows as $row) {
    		echo '<img class="alignleft size-thumbnail" src="';
    		echo $row['photo'];
    		echo '" />';
    	}
    	echo '</div>';
    }

    It now shows up properly in every page using that template.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.