I want to update postmeta value for a post by wordpess hook but i am not able to update it. Here is my code,
function check_values($post_ID, $post_after, $post_before){
$oldFob = get_post_meta( $post_ID, 'price', true);
if($oldFob){
update_post_meta( $post_ID, 'price', 500);
}else{
add_post_meta( $post_ID, 'fob-price', 500 , true);
}
}
add_action( 'post_updated', 'check_values', 10, 3 );
When I put die soon after update_post_meta
, and check db, it works but after coming back to edit post page, it reverts.
Basically it is updating post meta but after it, there is another default wordpress function run and reset it to old value.
Any expert suggestion, why its happening so??