I am using WP Post Views plugin to display the post number of views. To do so, I use:

<?php if(function_exists('the_views')) { the_views(); } ?>

This plugin gives 3 choises in its setting :

  • Count Views From Everyone
  • Count Views From Guests only
  • Count Views From registered users only

My website is a private community of authors. I have created some badges that are awarded automatically if some conditions are met.

For example, I award a badge to an author when its post attain a certain number of views by the other members of the community. (I use add_action( 'update_post_meta', 'award_badge' on the meta field updated by the_views(); )

The problem is: The plugin I am using can increment the number of a post views if the author himself see it. It will be good if the number of views increase only when other authors see the post.

I hope my explanation is clear enough. I thank you for your time.

Questions: Is there a plugin that provides this feature of excluding its own post visits from views count?

Is there a piece of code that can be a starting point for me to create a post count views plugin?

You usual help is appreciated.

Edit after S_Ha_Dum comment:

The link to the code source is :http://plugins.trac.wordpress.org/browser/wp-postviews/trunk/wp-postviews.php

  • It shouldn't be that hard to do but may require a plugin hack, which is discouraged. Can you post the plugin code that manages counting/setting the views? Or provide a link to that code? Hopefully, there is a filter.
    – s_ha_dum
    Jun 11, 2013 at 14:57
  • Ok dear @S_ha_dum, Can I post the code of the plugin as an edit? Or it will be better to give a link to the code? Jun 11, 2013 at 14:59
  • The plugin has a trac. I have already found it. A link to that should be fine.
    – s_ha_dum
    Jun 11, 2013 at 15:01
  • Totally agreeing with you, I give the link as an edit. Thank you very much for your help. Very hard for a beginner to find where to perform the hack. I am trying to understand this code. Jun 11, 2013 at 15:02

1 Answer 1


The plugin appears to be processing the view on the wp_head hook. That means you ought to be able to do something like this:

function remove_view_counter_wpse_102637() {
  global $post;
  $current_user = wp_get_current_user();

  if (
    && !empty($current_user)
    && $post->post_author == $current_user->ID
  ) {
    remove_action('wp_head', 'process_postviews');
add_action('wp_head', 'remove_view_counter_wpse_102637',1);

No guarantees. I don't use that plugin and can't test that, and the conditions may not be exactly right, but that concept should work.

  • Thank you very much dear @s_ha_dum, I will come back to give a feedback after implementing your idea. Thanks again Jun 11, 2013 at 15:29
  • I believe the remove_action on the callback process_postviews is the solution. Unfortunatley it is still not working even if I changed get_currentuserinfo() (which doesnt work for me in previous operations) with $current_user= wp_get_current_user(); .. I will keep digging based on your idea Jun 11, 2013 at 15:48
  • Perfectly working after changin '!=' by '=='. Thank you very much, you wrote the code, and I was inattentif reading it. Jun 11, 2013 at 15:51
  • today I learned from you that there is a concept called : possibility to hack plugins. In the future I will be using remove_action. Thank you very much Jun 11, 2013 at 15:56
  • Dear S_HA_DUM. How can I exclude also the duplicate views from same user during the same login session? How can I express is inside conditional if. Thank you very much . wordpress.stackexchange.com/questions/104324/… Jun 26, 2013 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.