Support › General › Same value for a specific custom field of all posts of a CPT
I'd like to know what the best practices are for dealing with the following situation.
I have a CPT with 2 custom fields (one is basic text and the other is an image) that have the same value for all posts.
The value of these CFs may change over time. Is there a way to change it in one place and have it affect all the posts in the CPT?
Many thanks in advance!
If you have the same field value for all posts, you can consider using a settings page. Then change the field value in one place for all posts.
Thank you Peter.
Just to be sure, I didn't say all the CF are common to all posts of the CPT (only some).
Would it still work?
Otherwise, another option would be to simply change the value directly in the database with some magic formula (that I don't have... yet). What do you think?
I don't know the magic code like that. If the field value is the same for some posts not all of them, you will need to update the value manually.
Or use the code like update_post_meta() within a loop.
Hello Péter, I'm sorry because reading your reply, I realize my last comment mislead you.
What I meant IS:
- some CF of my CPT have the same value for all posts and I'd like to bulk change them from time to time,
- others CF have a unique value for each post of this CPT.
In that case, is the settings page still a viable option according to you?
Or would it be the solution only if all the CF of that CPT had the dame value for all posts?
Use the settings page that lets you save/update the value in one place. Then you still need to use the custom code to update the value for fields in other posts. There isn't a solution with a few clicks to do that.
I hope that makes sense.