Support

Account

Home Forums General Issues render_field from field array

Solving

render_field from field array

  • I’m trying to create a plugin that will add a Field-Type to ACF, let say “Game” field type.

    This Game field will be a “Group” field that contains a set of 8 sub fields (buttons, inputs, files, images) with Conditional Logic between them.

    I created a simple field, set it as Group, added all required sub-fields, extracted to PHP code, and deleted it. No I have an array of the required group field.

    I want my <render_field> function to render the admin form fields from that array, instead of writing entire HTML code to the form and logics and everything…

    Is that possible?

  • ACF will not do anything with a field that is not defined by acf adding the field groups and fields by one of the methods allowed, i.e. defined in the admin, defined by adding fields with PHP, or defined in a JSON file.

    The way to do what you want is to create a field group and then clone that field group into the group where you want it do appear. Or you could add our fields by adding to a group using PHP.

  • Is it possible to define part of the fields in ACF admin and part with PHP withing the same group? If so maybe I can “replace” a field with some PHP?

  • Another idea – a field type called Game, that will actually be a clone field of specific group/field. It will make the field adding much much quicker. possible?

  • To your first question, yes. You can use the acf/load_field_group hook. This is an undocumented hook and you’ll need to look into the code in ACF. You can use this filter hook to manipulate the fields in the group.

    As for the second, you are not creating a single field, you are creating multiple nested fields. It would probably be possible to cram all of it into a single field type by creating a custom field type.

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

You must be logged in to reply to this topic.