Support

Account

Home Forums Gutenberg Repeater Field not working in Block Preview mode

Solving

Repeater Field not working in Block Preview mode

  • When I use a repeater in a Block, the preview isn’t loading the data properly. For example: I have a Carousel block with a Text field and a Repeater field. The Repeater field contains an image field. When I add my new Carousel block to my page, I can edit just fine, I add a title and 2 photos within the Repeater field.

    Then in the callback php I have the following:

    
    $title = get_field('title');
    $carousel = get_field('carousel');
    echo $title;
    echo '<pre>'.print_r($carousel,1).'</pre>';
    

    When I switch to Preview mode in the block it outputs the following:

    Testing

    Array
    (
    [5c12f0d68cc12] => Array
    (
    [field_5c12ecd7a3615] => 32
    )

    [5c12f1a48cc13] => Array
    (
    [field_5c12ecd7a3615] => 33
    )

    )

    As you can see, the Title field outputs properly, but the Repeater array is not using keys I can use to access the photos and it is only returning the ID of the photo in the array instead of the Photo array that it is set to return.

  • This actually only seems to affect image fields, as adding a text field in the Repeater after the photo shows the correct key for the text field when I print_r the Array.

  • I know this was asked about 3 years from the time of my comment but still I am going to post it.

    Today I was doing something similar and I faced the same challenge, on the template to render I was using have_rows() function, I switched to get_field() and a traditional php foreach and the preview worked as expected.

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

The topic ‘Repeater Field not working in Block Preview mode’ is closed to new replies.