Title: A user variable whose versions are also saved.
Last modified: August 24, 2016

---

# A user variable whose versions are also saved.

 *  [benpines](https://wordpress.org/support/users/benpines/)
 * (@benpines)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/a-user-variable-whose-versions-are-also-saved/)
 * I have a diet site. I want to add a variable to wordpress called “weight”, so
   users can fill their weight.
 * My question is – How can all past versions of “weight” that people fill also 
   be saved? I want to create a timeline for all the weights they filled.
 * In what WP database should I create this object?

Viewing 1 replies (of 1 total)

 *  [Richard](https://wordpress.org/support/users/richardcoffee/)
 * (@richardcoffee)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/a-user-variable-whose-versions-are-also-saved/#post-6167890)
 * One way could be to make the “weight history” an array using a date string as
   the index. Then just save it as user_meta using the ‘personal_options_update’
   filter.
 * add_action(‘personal_options_update’, ‘update_weight_history’);
    function update_weight_history(
   $user_id) { if (current_user_can(‘edit_user’,$user_id)) { $weight_history = get_user_meta(
   $user_id,’weight_history’); $weight_history[date(‘Y-m-d’,time())] = floatval(
   $_POST[‘weight’]); update_user_meta($user_id, ‘weight_history’, $weight_history);}}

Viewing 1 replies (of 1 total)

The topic ‘A user variable whose versions are also saved.’ is closed to new replies.

## Tags

 * [tables](https://wordpress.org/support/topic-tag/tables/)
 * [variables](https://wordpress.org/support/topic-tag/variables/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [Richard](https://wordpress.org/support/users/richardcoffee/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/a-user-variable-whose-versions-are-also-saved/#post-6167890)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
