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.
Related Posts:
- Double count view in archive.php
- Count the total views of all user posts published
- How to mark every 3rd post
- Count posts within a custom post type and specific taxonomy and terms?
- How to Display a List of Users Who Have Made at Least 1 Post?
- How to Display Network Post Count?
- How to cache a shortcode functions output?
- Count posts in category including child categories
- Writing a view count with w3 total cache
- Count singular post views automatically
- Add link on the top menu of the post table?
- Set font size automatically according to number of words in post
- Network wide post count (WP Multisite)
- Show post titles only on the homepage
- Show a list of recently viewed posts to a user
- Redirect based on user post count
- Alternate custom content in the loop
- Show that current post is number X out of X
- Show the author’s count of total amount of posts assign to a custom taxonomy term
- Sorting posts according to view counts not working
- Count to how many categories a post belongs to
- Count total number across post types
- Count search results in heading
- How to hide first gallery for every post?
- Make view count for pop up post
- Counter of posts ever posted – even deleted ones
- Display Published Posts Count for Certain Time Period
- Display Notification Bar on Header on Certain Post Count
- Show posts count for Categories and Tags in wp_nav_menu
- Gather posts into a cart/lightbox and share with another user
- How to add category post count in main navigation menu [closed]
- Count number of posts of current month
- Howto show comment count by post in post?
- Counter is skipping post when I still want it visible [closed]
- Display a list of users who have viewed the post you are viewing
- Count several post tags
- restrict incrementation of post vies count when refreshing the page
- Get post number both in the loop and in the post
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- Count the number of a post types associated with another post type
- Show number of posts by logged in user
- How get top post view for today for today post
- Echo the number of posts being displayed
- Display amount of pending posts in back/front end
- How to store array in usermeta in wordpress
- Count user posts and store the number for later use
- why the posts queried from sql is more than those showed on the page?
- sort posts by getPostViews in functions.php
- Author post count in category
- Set post title font size automatically according to number of words in post title
- How to show post views shortcode data for each post on Posts List Page?
- Show post count in custom taxonomy page
- Count singular post views automatically
- How to count posts in tags within time limit
- Add view to admin menu to filter for specific criteria ( If post is child of specific Parent )
- Display Custom Post Category Count & WordPress Category Count Using Shortcode
- Counting Posts by Category
- How to Display Most View Post in the template file?
- Display number of post published every day
- Retrieve posts inside foundation tabs and tab-content split by 3 per row
- Alternative content between posts no repetition
- Update user meta when post published no working
- count_posts to a standalone link
- How to control Post view count incresing in sidebar widget posts too?
- Count how many posts a user has viewed
- How to mark every 3rd post
- Add a minimum word count to Excerpt (and how to force Excerpt as a rule for WyPiekacz)
- How to limit the number of posts a user can publish based on user type
- ho can I get the number of the current post instead of the post id?
- post_count not working
- How to show total view count across all posts for an author
- Adding Count Post in Page
- Count words for all posts by all authors
- Word count for all posts of all authors
- Display post count on archive page in reverse order
- When inserting media file in a post or page, show file name under the thumbnail
- How to get total posts count for each date?
- Comment count next to post title?
- Next / Previous post in a single category
- view a list of 3 future post, from the nearest to the most far
- Adding a ‘section’ to the backend menu
- Secretly passing post ID/title etc into a shortcode form automatically to link submission to post
- Post title spoiler how?
- Pagination (on the static front page) shows always the same posts
- Get the total Author Favorited posts
- Automatic Table of contents with categories and posts
- Author.php Page views counter
- Odd hyphen added at end of blog post
- load post data into mysql
- Loop and output 4 rows of posts on home page
- Code to display random ordered posts in Categories across pages [duplicate]
- filter posts based on menu_order
- Bulk Post update_post_meta
- Detect if the currently opened document is a post
- More Than 50K Categories and WordPress Admin Panel Stop Showing Categories and Posts
- Hiding the name of the user who is currently editing
- Loop through taxonomies and loop through their terms (Newbie question)
- Spam written by registred users
- Get posts from category from custom query
- allow editor/author to publish others posts but not publish their own