• 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

    (@richardcoffee)

    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.