Home › Forums › ACF PRO › Programmatic post insertion, ACF fields, and the save_post hook › Reply To: Programmatic post insertion, ACF fields, and the save_post hook
I’ve made some progress – ACF fields must be added to the post following the wp_insert_post()
call if they are to be used in the theme!
In V4, it seems that calling update_field would add the data to the post and calling get_field() ultimately returned something regardless of whether the post had been updated or not.
In V5, calling get_field() on uninitialized fields will return NULL until the post is updated through the WP admin!
My theme was doing logic checks to see if a field was true or false before printing some text. Before upgrading, it didn’t matter if the ACF field was actually populated with data, but now it seems that the field will not return a boolean value (instead returns null) if update_field() was never called.
Simple solution – call update_field()
on all ACF fields directly following the wp_insert_post() call!
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.