I thought you wanted to load a field group, not populate fields with data.
What type of fields? What are the fields associated with? A post? something else? When do you want to populate the fields? when a post/whatever is edited? Some other time?
There are plenty of topics on the forums that cover populating fields with content but you’re going to need to give specifics, a more thorough explanation of what you want to do.
I have 2 text fields in my field group. The field group is associated with user role at the moment, but that might change in the future to a admin menu page. If possible, I’d like to run a manual upload of the data at startup of the wordpress server since I just need to grab the data from this field group.
The main purpose of this field group is to keep data for a table to show which ids and names are related.
In any case,
You can alter a value using an acf/load_value hook. In your filter you would test to see if there is already a value and if not then you can substitute some other value.
If you want the substituted value to be saved then you would use the update_field() function to do that inside of your acf/load_value filter.
Hi, sorry for the late reply. For the role bit, I was referring to the field group’s location rules. I’m assuming location rules defines who/where can access the field group.
Also, is there a function call to grab all the values in a field group in one go? So if I have two different fields in a field group, I can get an array of said values. Will this list be the same each time I call it as well?
I have had luck in the past storing JSON strings in text area fields.
Is it necessary to use an ACF field? Is this something that needs to be editable? If not then why not use a standard WP meta value. You can save store and retrieve array values using update_post_meta() and get_post_meta().
Well, editing a JSON string is not going to be easily usable. Have you looked at using a repeater it will return an array. It may not store it as you want but it would be editable and you could build your array from it. A group field also returns data as an array but it limited to one row.
You would have to decode it into an array, update the array values of the array and then json encode it again before updating. There would really be no way of editing it directly in the ACF field because even the slightest error in the json text would invalidate it and return nothing when decoded.
I see. I’ll keep that in mind, thank you.
So just to make sure, if I want to save data to the field directly, do I use the update_field function? I’m trying to implement a save function within an admin page so I don’t have access to normal posts and such. This is all done in a php file.
You must be logged in to reply to this topic.
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!