WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

I am creating a badge system for my wordpress site. My actual goal is to create a badge for number of post views: If a post has a number of views exceeding a certain threshold, then the author is awarded this badge.

How can I achieve this using action hooks? Till now, all the badges I have created use the priciple of action hooks (For instance, the badge related to the number of an author published posts uses post_publish action hook). Should I look for another approch for the views badge other than hooks?

Thank you for your help.

share|improve this question
Does the WP Post Views plugin that you're using have any functions that return a post's view count? If so, you should be able to award the badge based on that number. (I'd suggest adding the badge(s) to the user's meta information.) – Pat J Jun 5 '13 at 18:19
Thank you @PatJ, This is exactly what I am doing. – whiteletters in blankpapers Jun 6 '13 at 8:36
up vote 1 down vote accepted

Use the action from update_post_meta():

    "updated_{$meta_type}_meta", // example: updated_post_meta
    $object_id, // post ID
    $meta_key, // 'view'
    $_meta_value // view count

Something like this should work (not tested):

add_action( 'update_post_meta', 'badge_check', 10, 4 );

function badge_check( $meta_id, $post_id, $key, $value )
    if ( 'views' !== $key or 1000 > $value )

    $user = wp_get_current_user();

    if ( ! $user->ID )

    update_user_meta( $user->ID, 'badge', 'Kilo viewer' );
share|improve this answer
thank you @toscho. It is the starting point for a big knowledge I am running through. In fact your answer guided me to many other SE topics that I am trying to understand now. I will be back here to edit and accept your answer when correctly implemented. Have a good day. – whiteletters in blankpapers Jun 6 '13 at 8:39
please what do 10 and 4 refer to?? thank you – whiteletters in blankpapers Jun 7 '13 at 18:16
@whitelettersandblankspaces 10 is the priority and 4 the number of accepted arguments. – toscho Jun 7 '13 at 18:31
thank you very much @toscho – whiteletters in blankpapers Jun 7 '13 at 18:33

Your Answer


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.