Hello,
When adding a new field to an existing field group that belongs to a post type with many existing posts, how do we fill that new field with some sort of default data for all the existing posts?
Thanks
There is no way to add a default value to a field for existing posts.
You would need to write a script you run once to populate the database (you can add a code snippet at Toolset > Settings > Custom Code and run once, rather than activate).
You would need to get all the posts of the type in question (using get_posts), the loop over the posts and for each one use add_post_meta with the unique attribute set to true to provide a default value, while not overwriting existing values if they exist.
https://developer.wordpress.org/reference/functions/get_posts/
https://developer.wordpress.org/reference/functions/add_post_meta/
hidden link
That sounds like a big ask for people who don't know how to code.
I'd like to make a feature request that when adding new fields, we are provided a text field where we can enter default data that will be inserted into that field in all pre-existing posts.
Thanks
Hi Peter,
To open a feature request you will need to go to the link below.
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
From there you will need to provide as much detail about the feature as possible.
Once you've submitted the feature request it will be reviewed by our team and assigned a priority based on user requests for said feature.
It should be noted as well that this can take a bit of time to go through the entire process
Thanks,
Shane
Will submit a feature request.