How to Update Custom Fields with Default Values For Existing Posts when using ACF

Let's take a scenario where there are 10 Pages in a WordPress site.

You proceed to create a Text-type of custom field called, say, "Custom Title" using ACF for Pages and set its default value to "This is the default value" (not the most practical, but just to illustrate...).

When a new post (of the post type to which the field group is attached) is added and the field is left empty, the Custom Title post meta will be created and updated with the default value after the Publish button is clicked.

What about the existing Pages?

Unfortunately, the post meta does not exist for them and hence the default value does not appear.

Unless you edit each of those 10 Pages manually and click the Update button.

This is not a problem with a few posts, but what if there are 100s of posts?

This Pro tutorial shows how we can loop through the posts (Pages, in this example) for which our custom field is empty and update the field for each.

Step 1

Edit your field group.

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Instant access to 390+ Bricks code tutorials with BricksLabs Pro