Advanced Custom Fields Repeater

Community Forums Forums Design Tips and Tricks Advanced Custom Fields Repeater

This topic is: resolved

This topic contains 4 replies, has 2 voices, and was last updated by  Simon Abramson 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #92323

    Simon Abramson
    Member
    Post count: 8

    I’m having trouble displaying info that’s stored via ACF’s Repeater Add-on.

    ACF suggests using the following, but I’m not sure how to make this play nicely with Genesis.

    <?php
     
    // check if the repeater field has rows of data
    if( have_rows('repeater_field_name') ):
     
     	// loop through the rows of data
        while ( have_rows('repeater_field_name') ) : the_row();
     
            // display a sub field value
            the_sub_field('sub_field_name');
     
        endwhile;
     
    else :
     
        // no rows found
     
    endif;
     
    ?>
    #92337

    Peter
    Participant
    Post count: 95

    Does it work with other themes? Just a problem with Genesis? I’m not familiar with this addon but from the look of that code it looks like it belongs in the html of a template file (e.g, single.php, page.php, etc). I’m stating the obvious but it’s probably best to ask the addon creator about this.

    #92352

    Simon Abramson
    Member
    Post count: 8

    Peter — this’ll work in any theme.

    I’m just not sure how to inject this PHP code into my single.php using a Genesis child theme. I would usually just edit the single.php file or another php file in the template hierarchy. Not so with Genesis though.

    I know Genesis has genesis_custom_field for calling custom fields… how would I mesh genesis_custom_field and if( have_rows(‘repeater_field_name’) ): etc…

    #92361

    Peter
    Participant
    Post count: 95

    Where do you want that data to appear in your theme specifically? Since it already works, then it’s just a matter of adding it to the markup. Did you try something like this? In the functions.php file:

    function test_repeater_field_name() {
      if( have_rows('repeater_field_name') ):
        while ( have_rows('repeater_field_name') ) : the_row();
            the_sub_field('sub_field_name');
        endwhile;
      else : 
        // no rows found 
      endif;
    }
    add_action( 'genesis_loop', 'test_repeater_field_name' );
    #92471

    Simon Abramson
    Member
    Post count: 8

    Thanks Peter! I realized it was that simple last night while washing some dishes.

    Funny how things click after some time.

    – Si

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

You must be logged in to reply to this topic.