Support

Account

Home Forums Backend Issues (wp-admin) Using Repeaters and Flexible Content in new Field Types Reply To: Using Repeaters and Flexible Content in new Field Types

  • I didn’t reply sooner, I had thought to try this out, but I haven’t had time. It’s a lot of building to do to test a theory. I certain that it can be done though. When I was building the add on that I built, well, I just tried it and played with it until I got it to work. I had a specific need for a client, so I had the time. Frankly, if it had not worked I’m not sure what I would have done.

    The ACF field type template https://github.com/elliotcondon/acf-field-type-template includes several methods that are commented out, load_value(), update_value(), render_field() and format_value() are the important ones.

    I’m guessing that you want a real “value” + you want to add these additional settings.

    In update_value, you would need to look in the ‘$_POSTarray to get the values from the repeater field and then do something with the actual value of the field and these extra settings to store them in an array before they are saved to the database. The big question here is what does the submitted value look like? Which ties into the comment below aboutrender_field`

    In ‘load_valuewhat you'd need to do is to extract the actual value from the field and then store your additional settings into some custom field argument, for example$field[‘custom_settings’]`.

    In render_field, this is the part that’s a guess, but you should be able to set up a repeater field simply by calling one of the build in ACF functions that does this, possibly acf_render_field_wrap() or acf_render_field() or maybe even running the action do_action('acf/render_field', $repeater)

    Then you have format_value that would do the work of taking the “value” and applying your custom options from the repeater to it.

    The question is, how much time do you have and how much time and frustration will is save the person that needs to use it. Only you can answer the question. In my case I had to give the client a way to add formatting to single lines of input that would be used for headings throughout the site and this also included the ability to apply specific colors to specific portions of the text. My choices were to build a field type or to implement some type of “markdown” in text fields or textarea fields. If I had gone the markdown path what would have happened is that the client would not have been able to manage this content themselves and I would have ended up doing the work anyway. So not only does the field type I created make it possible for the client to easily do the work themselves, it saves me a boatload of time that I would have been spending managing their content, far more time than it took me to create the field type. This is what I weighed the time to create the field type against, how much time will it save me later.

    I can tell you one thing though. I will be keeping this conversation in mind on future projects. I find the possibility of doing something like this extremely interesting, as if you probably can’t tell that by this extensive comment :P. I will also probably investigate this if I ever manage to find some free time even if I don’t find a specific need.