Thanks! That was very helpful. What I was trying to do was loop through a certain set of post types and dynamically add them as subfields of a group along with a bunch of subfields for each post type.
You were correct that I should be doing it when the group field is registered, not when it loads.
Also, all field keys should start with ‘field_’ not ‘sub_field_’. I still could not get the options to save, however, because of another problem.
Because I was using a foreach loop to create the subfields on each post type, I was using a random number on each pass through the loop, trying to prevent duplicate field keys.
What I didn’t realize was that this meant the field keys kept changing. Every time I tried to save options, the field key would change, so of course nothing was saving in the database!
So, to fix it I just had to use the post type in the field keys instead of a random number. That way they would be unique AND permanent. Problem solved!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2023 Advanced Custom Fields.