Forums

[Plugin: WP-PostViews Plus] Monitoring Users Post Views (1 post)

  1. adam.sykes
    Member
    Posted 2 years ago #

    If you wish to keep track of the tags which users frequently visit as well as the posts they visit, and on a per user basis. Add the following code after the lines:

    $post_views = intval(get_post_meta($post->ID, 'views', true));
    					if( !update_post_meta($post->ID, 'views', ($post_views+1)) ) {
    						add_post_meta($post->ID, 'views', 1, true);
    					}

    in the file postviews_plus.php, the data is stored in the usermeta table with the field name of tagview_ and then the name of your tag.

    CODE TO ADD BELOW

    //User Tracking Code
    					global $user_ID;
    					get_currentuserinfo();
    					$posttags = get_the_tags();
    					if ($posttags) {
    						foreach($posttags as $tag) {
    							$meta_key = "tagview_" . $tag->name;
    							$tag_views = intval(get_usermeta($user_ID, $meta_key, true));
    							echo $tag_views;
    							if( !update_usermeta($user_ID, $meta_key, ($tag_views+1)) ) {
    								update_usermeta($user_ID, $meta_key, 1);
    							}
    						}
    					}
    					//End of User Tracking Code

    http://wordpress.org/extend/plugins/wp-postviews-plus/

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 2 years ago by adam.sykes
  • This topic is not a support question
  • WordPress version: 2.8