Home › Forums › General Issues › Add data to ACF fields on post creation? › Reply To: Add data to ACF fields on post creation?
You need to create the post first and then add the fields using the update_field() function https://www.advancedcustomfields.com/resources/update_field/ to update each field. You will need to use the field key for $selector when doing this. You’ll also need to make sure that you’re using the right type of value depending on what type of field you are updating, so you’ll need to investigate how ACF stores the needed values or if there are any special requirements for the $value of a specific type of field.
It might be possible to update it all at once using wp_insert_post(), however, this will require understanding how every type of field is actually stored in the database as well as making sure that you also add the correct field key references for every field. Doing it this way would be much more complex than using update_field()
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.