update_post_meta updates to previous revision value
-
I have a couple of values (in meta fields) set when creating or updating a post. In my functions.php I iterate through all the these values when saving and update the value. The problem is that when changing to a new value, the code below will set the value from the previous revision.
$captionData = $_POST['caption_value']; if(get_post_meta($post_id, 'caption_value') == "") add_post_meta($post_id, 'caption_value', $captionData, true); elseif($captionData != get_post_meta($post_id, 'caption_value', true)) update_post_meta($post_id, 'caption_value', $captionData);
Example:
Revision 1: set ‘caption_value’ to “foo” -> post_meta remains blank
Revision 2: set ‘caption_value’ to “bar” -> post_meta returns “foo”
Revision 3: set ‘caption_value’ to “foo2” – post_meta returns “bar”
etc…Elsewhere in the theme the code below works like a charm:
$data = $_POST[$meta_box['name'].'_value']; if(get_post_meta($post_id, $meta_box['name'].'_value') == "") add_post_meta($post_id, $meta_box['name'].'_value', $data, true); elseif($data != get_post_meta($post_id, $pre.'_value', true)) update_post_meta($post_id, $meta_box['name'].'_value', $data); elseif($data == "") delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));
I’m not sure if my problem is in understanding update_post_data, the $_POST variable or even if it has something to do with $pre (a variable which never seems to be set anywhere.
Any guidance will be greatly appreciated!
- The topic ‘update_post_meta updates to previous revision value’ is closed to new replies.