Support

Account

Home Forums Feature Requests Repeater/Flexible Content version of setup_postdata()

Solving

Repeater/Flexible Content version of setup_postdata()

  • I’ve run into a situation where it would be helpful for me to be able to arbitrarily set what field the current instance of have_rows() and the_row() reference (as well as related functions, get_sub_field(), etc). Similar to how you can use setup_postdata() to effect the wordpress loop-dependent functions (the_title(), the_content(), etc).

    The origin of my problem is with clone fields, as to use grouped clone fields you need to access them as arrays – this breaks the normal nesting of have_rows / the_row, and ability to call get_field / get_sub_field, etc. If I could just pass in the field data array to something like setup_fielddata() to point ACF’s template functions at the correct data, it would be quite helpful in standardizing much of this code.

    As far as I can tell, there isn’t a way to do this currently.

    Thanks

  • No, there is nothing in ACF that does this. You’d need to write your own function that gets the values and returns them as an array. But I was not aware that grouping cloned fields breaks any or the other functionality in ACF. Maybe what you are looking for is explained in the documentation for the clone field https://www.advancedcustomfields.com/resources/clone/

  • The particular limitation is listed in the documentation:

    “2. have_rows() nested clone field

    The have_rows() function will return false when loading a cloned sub field using the ‘Display = Block’ setting. Please note that using the ‘Seamless’ display setting will allow sub have_rows() loops to work as expected.”

    Unfortunately the Seamless display mode doesn’t work for my purposes, so I’m stuck with grouped. I know Elliot has mentioned trying to remove some of these limitations in the past, so this is in part intended to be a suggestion on how he might accomplish that. Beyond that though I can think of some non-clone field applications where such a thing might be handy.

    I’ve already written replacements for the various ACF functions for my own use case, but I’d prefer to be able to use the standard ACF code for consistency.

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

The topic ‘Repeater/Flexible Content version of setup_postdata()’ is closed to new replies.