Home › Forums › Backend Issues (wp-admin) › update multiple fields at once through functions.php › Reply To: update multiple fields at once through functions.php
There isn’t an easy way to do this. You will need to
1) Get all the posts of the post type
2) Check to see if the field already has a value
3) update if it doesn’t
Depending on the number of posts involved, this process could very well time out before completion.
The better alternative is to set a default value if the field does not contain a value.
$value = get_field('field_name');
if (!$value) {
$value = 'set some default value';
}
The checking of this may need to be more complex, but that’s the idea.
Alternately you could add an acf/load_value filter to the field and return a default value from this and this would not require altering templates where it’s used 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.