• function addOne() {
    	$user_id = $_SERVER["QUERY_STRING"];
    	$key = 'viewcount';
    	$view_count = get_user_meta($user_id, $key, true);
    	$view_count += 1;
    	echo 'view_count is:'. $view_count;
    	update_user_meta($user_id, $key, $view_count);
    	return $view_count;
    }

    Each time I visit https://www.mysite.com/single-page?15

    This function should increase by one the custom meta field “viewcount” related to user 15

    It’s almost working… except that instead of increasing by one it’s increasing by two the field.

    (The function is written in function.php (of the theme I’m currently using) and I call it from the html content of a post using a plugin to execute Php, just to call it)

    What’s wrong?
    thank you!
    Giacomo

Viewing 1 replies (of 1 total)
  • Is this attached to a hook? If so, that hook could be firing more than once…

Viewing 1 replies (of 1 total)
  • The topic ‘update_user_meta not working properly’ is closed to new replies.