Jump to content

Repeater field in child page loop keeps showing same field data for all child pages


Recommended Posts

Something probably off with my loop, the code below is on my "entries.php" template page, it's outputting the title and description of each entry fine but the repeater fields just repeats the first set of images from entry 1 throughout the loop.


// Functions

  $entries = $page->children;
  $entry_array = array();
  $image_array = array();
  foreach ($entries as $entry) {
    // Define the fields wanted
    $title = $entry->title;

    $description = $entry->entry_description;

    $images = $entry->images;
    foreach ($images as $image) {
        $imageUrl = $image->url; // make a thumb version
        $imageDescription = $image->description;
        // Build array from repeater
        $image_array[] = array(
            'image_url' => $imageUrl,
            'image_description' => $imageDescription,

    $pageUrl = $entry->httpUrl;

    // Build the array from the fields
    $entry_array[] = array(
          'title' => $title, 
          'description' => $description,
          'images' => $image_array,
          'page_url' => $pageUrl,
  // Json encode the array
  $entries = json_encode($entry_array, true);
  // Dump the data
  // echo $data;  



Link to comment
Share on other sites

I figured this out, it's because I had no 'images' for other entries so the variable array was been set and never re-set/assigned in the loop.


Now I have an if (count($images)) wrapper and else I can just spit out the entry array when count is empty.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...