In a WordPress blog, I want to use in each post add_post_meta
like in the following example:
add_post_meta( 7, 'fruit', 'banana', true )
If I want to set a different fruit for this post later, what is it going to happen? I mean the value will be replaced or added?
I just want to be sure it is always overwritten and replaced with the new one (always 1 value), NOT added. Obiously each post will have its value.
You can use update_post_meta
(you don't need the true
parameter in this case). The function will create the meta if it does not exist or will update it if it does.
Codex: https://codex.wordpress.org/Function_Reference/update_post_meta
To answer your original question add_post_meta
will add multiple fields with the same key if the true
parameter is not used, otherwise no changes will be made.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.