Home Forums ACF PRO Dynamically add fields based on repeater values


Dynamically add fields based on repeater values

  • I’m working with a client that wants the ability to set a group of fields for several categories. The fields will need to be flexible and capable of being used in several categories. I know this can be competed by creating a field group and setting the rule ‘Post Category is equal to’ X and adding a rule group for each category that requires the fields. In this particular situation the client has eight ‘specifications’ with four or so fields each. This would mean creating eight field groups and adding rules to each. The client also wants to be able have two select field options and use the created specification field groups main field (title) to dynamically populate the select option values. I understand that I can can create a field group that applies to categories by setting the rule to ‘Taxonomy Term is equal to category’ and that you can set select option values dynamically by following the instructions on Dynamically populate a select field’s choices. But how would I look through all eight specification field groups and allow the client to add additional specification field groups in the future?

    In case it helps understand the situation, the client has equipment specifications that are required for all equipment (title, model, etc.) as well as specifications that are specific to the category (working height, horizontal reach, etc.).
    We want to build it so that the client doesn’t really have to understand what’s going on behind the scenes and if possible, would like for them to not have to enter into ‘Custom Fields’. A workable solution that was first conceived was adding a ’specifications’ options page for the ‘equipment’ custom post type with a ‘specs’ repeater field. The repeater field would allow the client to easily add specs by adding a row. We would also have a field group with the rule of ‘Taxonomy Term is equal to category’. The field group would include three select type fields with one allowing multiple values to be selected. These select type fields would have choices dynamically populated based on the option page repeater. The user can edit a category and make selections for each ACF. One of the fields (multi select) would be where they could select which specifications were needed for the category. All of this has already been completed but the tricky part is adding fields to the actual post based on the post category and the selections made for the category. How I would see it working would be dynamically adding fields to each post based on a loop that retrieved the selected values included in the category ACF.

Viewing 1 post (of 1 total)

The topic ‘Dynamically add fields based on repeater values’ is closed to new replies.