When a custom field (text type to keep it simple) with a default value is created for a post type, say page
, any new Pages created from that point onward will have that post meta with the default value when the Page is published/updated.
But already existing Pages will not have the post meta unless we go in each and update them. This is fine for a few Pages but not ideal for larger sites.
What is the recommended method for programmatically updating the post meta for existing Pages with the default field value?
I tried writing the following in a function hooked to init that loops through Pages where the custom field in question does not exist
$default_value = rwmb_get_field_settings( 'custom_title', '', $page->ID )['std'];
rwmb_set_meta( $page->ID, 'page_title', $default_value );
but it isn't working.