0

My plugin uses a metabox to save post meta. I have three option in the metabox. Everything is saving/updating/deleting correctly except for this:

add_post_meta( $post_id, $meta_key_duration, $new_meta_value_duration, true );

If I echo out the values right before this call:

echo $post_id.' '.$meta_key_duration.' '.$new_meta_value_duration;

I get:

52 expDuration 10

this is correct since I chose "10" as the value to be saved. The database is showing the post_id and meta_id correctly but the value isn't being saved.

  • add_post_meta( $post_id, $meta_key_duration, "4", true ); isn't saving "4" into the DB either – dcp3450 Apr 3 '14 at 22:41
0

If you're updating a value, you want to use update_post_meta. When you set $unique to true in add_post_meta, nothing will happen if the meta key already exists.

0

Just use update_post_meta() which will make sure that $meta_key already exists. If it does not, add_post_meta is called instead and its result is returned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.