Skip Navigation

[Resolved] Add Content to New Field For Existing Posts

This support ticket is created 2 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 4 replies, has 3 voices.

Last updated by peterR-3 2 years, 11 months ago.

Assisted by: Shane.

Author
Posts
#2279683

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

#2279739

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

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

#2280033

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

#2280063

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

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

#2280071

Will submit a feature request.