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.

  • 1
    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, 2013 at 18:19

1 Answer 1


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' );
  • 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. Jun 6, 2013 at 8:39
  • please what do 10 and 4 refer to?? thank you Jun 7, 2013 at 18:16
  • @whitelettersandblankspaces 10 is the priority and 4 the number of accepted arguments.
    – fuxia
    Jun 7, 2013 at 18:31

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.