Support

Account

Home Forums Add-ons Repeater Field How do you output repeater field in a table?

Solving

How do you output repeater field in a table?

  • Hi. I created a repeater field called, ‘piece_details’ which includes 4 sub fields which are,

    1. performer-name
    2. piece
    3. composer
    4. minutes

    I wish to output the data in a table with a heading using an Elementor template. I pasted the code below in the function.php file in my Child Theme. However, nothing is showing after I used the ACF repeater widget to output the data. What am I doing wrong?

    // check if the repeater field has rows of data
    if( have_rows(‘piece_details’) ):

    // loop through the rows of data
    while ( have_rows(‘piece_details’) ) : the_row();

    // get a sub field value (table field)
    $table = sub_field(‘performer-name’);
    $table = sub_field(‘piece’);
    $table = sub_field(‘composer’);
    $table = sub_field(‘minutes’);

    // use the “Output Table HTML” code with $table

    endwhile;

    else :

    // no rows found

    endif;

  • I forgot to add that I used the Dynamic Content plugin for the Repeater Widget in Elementor Pro.

  • Hi Polyspora!

    In a while loop, get your sub field with get_sub_field('field_name') and not sub_field.

    You can direclty display your field with the_sub_field('field_name').

    Cheers!
    Sam

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

You must be logged in to reply to this topic.