Home Forums Add-ons Repeater Field Set Dynamic Placeholders for Sub Fields


Set Dynamic Placeholders for Sub Fields

  • I have a situation where I need to pre-define some content within repeater fields. Basically, I need to have a set of fields that already have blocks of text defined but can be deleted or modified.

    I’m wondering if there’s any way to create a repeater field that has a pre-defined number of fields along with placeholder text for those fields. I don’t want to set a minimum because sometimes those fields will need to be deleted.

    I’m not sure if I’m explaining this very well… if it doesn’t make sense please let me know and I’ll try to explain it more clearly.

  • Hi @FATMedia

    This can be done in 2 parts.

    Part 1 is to create the default values for each sub field. This is possible through the normal field edit UI.

    Part 2 is to use a filter called acf/load_value. Pleae visit the docs page to read up on this filter. Use this filter to hook in and modify the repeater field’s value. If the value is empty (new post), then return an array. This will trick ACF into rendering the row of data using the default values set earlier.

    Does that help?


  • This part I understand, but the part I’m confused about is how to make unique placeholder text for a series of sub-fields. I’ll link to some screenshots which might explain my situation a little better…

    Here’s the setup, which doesn’t seem to allow what I’d like to do:

    Here’s what I’m trying to create, but can’t quite figure out how to do it:

    If it can’t be done through the GUI, that’s not a problem I just need a bit of direction for doing it progamatically.

  • Hi @FATMedia

    Sure. The easiest way to do this is to use the ACF filter called acf/load_value.

    You will find docs for this on the documentation page. Use it to hook into any value loaded for the repeater field.

    If the value is empty, this means that the post must be a new one, in this case, you can modify the value to trick ACF into rendering 3 rows of data.

    All you need to do is set the value to this format:

    $value = array(
    		'field_123' = 'Placeholder Title',
    		'field_456' = 'Placeholder text here...'
    		'field_123' = 'Another Placeholder Title',
    		'field_456' = 'Different Placeholder text here...'
    		'field_123' = 'Yet Another Placeholder Title',
    		'field_456' = 'Another Different Placeholder text here...'

    When editing the field group, you can toggle on ‘show field keys’ via the screen options menu tab. This will give you the sub field keys for field_123 and field_456.

    Hope that helps.


  • Awesome! Thanks for the help eliot. 🙂

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

The topic ‘Set Dynamic Placeholders for Sub Fields’ is closed to new replies.