Support

Account

Home Forums ACF PRO Repeater Fields & Actions/Filters

Solved

Repeater Fields & Actions/Filters

  • It is my understanding that none of the data manipulating filters or actions (e.g. acf/load_field, acf/load_value, etc) work with repeaters. Is that correct? I get a dynamic value, but it looks as thought the hooks are only called once.

    If not:
    What is there a filter that is fired every time an “Add Row” on a repeater is click.

    If correct:
    I have a repeater, in a CPT, with a read-only text field that I would like to auto populate with a value. What is the best way to do that?

    Should I be using, ‘acf/save_post’ and just loop though the data accordingly.
    I’d really like the value to be present on ‘Add Row’ of the repeater, but if that’s not possible, the I guess I’ll go with the alternative.

    Thanks.

  • There is a hook that is fired when a repeater is added, this is in JavaScript. See Adding custom javascript to fields and JavaScript API. The hook you are looking for is append.

    acf/load_field and other hooks should use the field key variation for repeater sub fields. However, most of these hooks only fire once per sub field. The acf/prepare_field fires on every instance, but this only fires for existing fields and will not work when a row is added to a repeater. There is also no way of telling what row of the repeater is being prepared for render.

    Without using JavaScript you would have to do what you describe in your last statement about using acf/save_post.

  • That’s actually pretty cool I wasn’t aware of the JS API.

    I figured I’d need to do some AJAX to get the functionality I wanted so I started writing up a little script. I used your suggestion from another post to check out some examples from Hube2’s Github Link

    While I got the base AJAX functionality going, this JS API might be a better/easier way to catch the events.

    Thank you!

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

You must be logged in to reply to this topic.