• I have a very simple code like:

    if (is_user_logged_in()) {
        $user = wp_get_current_user();
        $aka2 = get_user_meta($user->ID, 'last_visited_blogs', true);
        $aka2[] = 'akaki2';
        update_user_meta($user->ID, 'last_visited_blogs', $aka2);
      } ?>

    but even when last_visited_blogs are emty it just adds two values, and in db it array(2); with two ‘akaki2’

    whats wrong?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    If the table value initially does not exist, the only explanation is the code is executing twice, as $aka2[] = 'akaki2'; adds a new array element each time to $aka2. The array should keep growing every time the code runs. It’s not unusual for action and filter hooks to fire more often than you think, assuming that is how the code was initiated.

    If you wish to set a single value if none exists, you should use something like if ($aka2 == '') $aka2 = 'akaki2';

Viewing 1 replies (of 1 total)

The topic ‘update_user_meta adds duplicate’ is closed to new replies.