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 thetrue
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 thetrue
parameter is not used, otherwise no changes will be made.