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.

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

2 Answers 2

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 and acknowledge you have read our privacy policy.

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