update_user_meta as multiple value but with same meta key

Question

I have this code. When I save it, the levels adding and gives time select input next to it. But when I give different time to levels, for example: Level 1: 2 weeks, Level 2: 9 Months

If which the last element, the all inputs displaying that value of it. How can I save as different time? Where do I wrong?

  $user_levels = rua_get_user($user->ID)->get_level_ids(); // get user's level IDs
  $end_time = get_the_author_meta( 'time-selector', $user->ID); // get time meta
  $elements = array(); //the array of a user's level IDs

  $menu = "<select name='time-selector' id='time-selector[]' style='width:180px;'>
          <option value='default'>Select time</option>
          <option value='two'" .selected( $end_time, 'two'). ">2 Weeks</option>
          <option value='nine'" .selected( $end_time, 'nine'). ">9 Months</option>
          <option value='twelve'" .selected( $end_time, 'twelve'). ">12 Months</option>
          <option value='extend'" .selected( $end_time, 'extend'). ">Extend</option>
          </select>";

    foreach ($user_levels as $user_level) {
        $elements[] = get_the_title($user_level) . ' -> ' .$menu .'<br><br>';   
    }

   update_user_meta( $user_id, 'time-selector', $_POST['time-selector'] ); //save time meta
0
freedom667 2 months 0 Answers 10 views 0

Leave an answer