I’m not sure why are you hooking into the_content
filter. You could use a more appropriate action hook, such as wp_head
:
<?php
add_action ( 'wp_head', 'update_user_count' ); // note
function update_user_count()
{
global $post;
// Make sure you only get the int part
$counter = ( int ) get_post_meta( $post->ID, 'views', true );
// increment counter by 1
// http://php.net/manual/en/language.operators.increment.php
$counter++;
update_user_meta( $post->post_author, 'wpcf-count', $counter);
}
This should work as intended now, I have a similar piece of code to update my blog’s views count. But notice, global $post
only works properly in the loop. You should add some checks to see if you are in a loop, or if the $post
variable is actually set.