Basically, I'm trying to make a point exchange between current user and author when the post meta value is updated.
As well as add +1 to post meta.
Here's what I currently have:
// Coin exchange function
//
add_action( 'updated_post_meta', 'coin_exchange_after_post_meta_update', 10, 4 );
function coin_exchange_after_post_meta_update( $meta_id, $post_id, $meta_key, $meta_value )
{
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
$author_id = get_post_field( 'post_author', $post_id );
if ( 'postcoins' == $meta_key ) {
update_user_meta( $current_user_id, 'usercoins', ''); // subtract -1 from current user
update_user_meta( $author_id, 'usercoins', ''); // add +1 to post author
update_post_meta( $post_id, 'postcoins', '' ); // add +1 to post meta
}
}
The only thing that's left is to figure out how to subtract and add values.
I know there's a way using sum=0, but I'm struggling with the logic.
I would really appreciate your help.