Home › Forums › General Issues › New Field – Auto Update posts in custom post type › Reply To: New Field – Auto Update posts in custom post type
You need to loop through the posts and update the field, yes you could do that.
get posts
while have posts
the post
update value
But I wouldn’t.
The best way to do this is to check the value where it is used and substitute a default value if it’s not set, it only takes a couple lines of code to deal with it.
$value = get_field('your-new-field');
if (!$value) {
$value = 'the default value';
}
// do something with value
you could also add an acf/load_value filter for the field in question that sets the default value if it is empty https://www.advancedcustomfields.com/resources/acf-load_value/
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.