Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
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 '13 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? –  whiteletters and blankspaces Jun 11 '13 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 '13 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. –  whiteletters and blankspaces Jun 11 '13 at 15:02
add comment

1 Answer

up vote 1 down vote accepted

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 (
    is_single() 
    && !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.

share|improve this answer
    
Thank you very much dear @s_ha_dum, I will come back to give a feedback after implementing your idea. Thanks again –  whiteletters and blankspaces Jun 11 '13 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 –  whiteletters and blankspaces Jun 11 '13 at 15:48
    
Perfectly working after changin '!=' by '=='. Thank you very much, you wrote the code, and I was inattentif reading it. –  whiteletters and blankspaces Jun 11 '13 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 –  whiteletters and blankspaces Jun 11 '13 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/… –  whiteletters and blankspaces Jun 26 '13 at 12:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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