How to tell whether a user meta value has increased or decreased [closed]

I would solve this creating two extra Custom Fields:

  • _score_last
  • _score_variation

The first underscore makes the CF invisible in the Admin area.

Drop the following code in your theme’s functions.php:

if( is_admin() )
{
    add_action( 'save_post', 'wpse_57217_check_customfield_variation', 11, 2 );
}

function wpse_57217_check_customfield_variation( $post_id, $post )
{
    if ( 
        ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
        or ! current_user_can( 'edit_post', $post_id )
        or wp_is_post_revision( $post )
    )
    { // Noting to do.
        return;
    }

    $actual = get_post_meta($post_id, 'score', true);
    $last = get_post_meta($post_id, '_score_last', true);
    $last = ( '' != $last ) ? $last : '0';
    if ( '' != $actual ) 
    {
        if ( absint($actual) > absint($last) )
        {
            update_post_meta( $post_id, '_score_variation', 'up' );
        }
        elseif ( absint($actual) == absint($last) )
        {
            update_post_meta( $post_id, '_score_variation', 'stable' );
        }
        else
        {
            update_post_meta( $post_id, '_score_variation', 'down' );
        }
        update_post_meta( $post_id, '_score_last', $actual );
    } 
}

And for reference only, this inside the loop:

echo 'actual score: ' . get_post_meta($post->ID, 'score', true);
echo '<br> last score (value already updated): ' . get_post_meta($post->ID, '_score_last', true);
echo '<br> score variation: ' . get_post_meta($post->ID, '_score_variation', true);