Plugin Directory

Test out the new Plugin Directory and let us know what you think.

Post Views Count (Support caching plugins!)

This plugin counts views for post and pages, shortcodes [post_view] & [most_view] are available, also a widget "Most Viewed Posts" is.

How to use/display it?

  1. [post_view] will display the counter for the actual post, custom post or page.
  2. [post_view id="123"] will display the counter for the post/page ID "123".
  3. [post_view time="day"] will display the count view of the day. So same for "week" will display count view for this week.
  4. [post_view time="day" date="20120213"] will display the count view for this particular day: 13th, feb 2012. "date" can not be use alone, always use "time" in the same time.
  5. [post_view time="month" date="201102"] will display the count view for the last year february. This mean you can play with date in your template, kind of :
  6. echo do_shortcode( '[post_view time="month" date="' . date( 'Ym', mktime( 0, 0, 0, date("n")-1, date("j"), date("Y") ) . '"]' ); // This will always display the count views of the month of last year.
  • A shortcode named "most_view" (or "most_views" or "most_viewed") is available. Same as [post_view], you can set "time" and "date" but also this parameters:
  1. "before": A text before the list; default is empty
  2. "after": A text after the list; default is empty
  3. "show": Do we show counters ? 1= yes, 0=no; default is 1.
  4. "number": How many posts to display ?; default is 10.
  5. "ul_class": A CSS class
  6. "li_class": A CSS class
  7. "order": 'desc' or 'asc'
  8. "author": an author ID or author name.
  9. "post_type": post types list, comma separated, default=settings Example:

- [most_view number="3" show="0" before="Top 3!"] Will display the top 3 posts, no counters displayed, with title "Top 3!"

What are the hooks ?

  1. baw_count_views_timings: apply_filters( 'baw_count_views_timings', array( 'all'=>'', 'day'=>'Ymd', 'week'=>'YW', 'month'=>'Ym', 'year'=>'Y' ) ); You can add/remove timings with this filter, so if you do not need stats, or just do not need Year stat, you can remove them to avoid the creation of meta data unused in DB. Example:
function remove_timing_for_bawpvc( $timings )
    unset( $timings['year'] ); // remove Year stat/meta
    return $timings;
add_filter( 'baw_count_views_timings', 'remove_timing_for_bawpvc' );


function remove_timing_for_bawpvc( $timings )
    return array( 'all' => '' ); // keep only all counts, no other stats
add_filter( 'baw_count_views_timings', 'remove_timing_for_bawpvc' );
  1. baw_count_views_meta_key: apply_filters( 'baw_count_views_meta_key', '_count-views_' . $time . $date, $time, $date ); This hook is present to give compatibility with any old count plugins that had already record some counts for your blog. Example of use with wp-postviews: Its meta_key is "views" so i do this:
function modify_metakey_for_bawpvc( $data, $time )
    return $time == 'all' ? 'views' : $data;
add_filter( 'baw_count_views_meta_key', 'modify_metakey_for_bawpvc', 10, 2 );

This return "views" if the selected stats count is "all" ! You can also play with $time and $date to do some checkings.

  1. baw_count_views_count: apply_filters( 'baw_count_views_count', $count, $meta_key, $time, $date, $id ); You can modify the $count value here, depending on time, date or meta_key. I added this in case of ... You can avoid recording count on different date or cheat on counting x)

  2. baw_count_views_count_action: do_action( 'baw_count_views_count', $count, $meta_key, $time, $date, $id ); Same as above, you can run your own code here.

  3. widget_title This is a WordPress hook, see codex or core code.

  4. baw_count_views_capa_role: apply_filters( 'baw_count_views_capa_role', 'edit_posts' ); You can modify the capatibility or rolle needed to see and modify the posts views stats. Example:

function bawpv_count_views_capa_role( $capa )
    return 'administrator'; 
    // or
    // return 'manage_options';

1. *baw_count_views_render_post_columns*:

apply_filters( 'baw_count_views_render_post_columns', $post_id );` You can add (or remove?) more then only the "all" count stats in post page list in admin panel. Example:

function baw_count_views_render_post_columns( $post_id )
    echo '<br />';
    echo 'Month: ' . (int)get_post_meta( $post_id, '_count-views_month-'.date(mY), true );
Will display the month stats below the default "all" count.

1. *baw_count_views_widget_post_types*:

apply_filters( 'baw_count_views_widget_post_types', $post_types );` You can hack the post types displayed in widget, whatever the settings.

Requires: 3.1 or higher
Compatible up to: 4.4.8
Last Updated: 1 year ago
Active Installs: 30,000+


4 out of 5 stars


Got something to say? Need help?


Not enough data

0 people say it works.
0 people say it's broken.

100,1,1 100,1,1 100,2,2 100,1,1 100,1,1 100,1,1 100,1,1
100,1,1 100,1,1
100,1,1 100,1,1
100,1,1 100,1,1 100,2,2 100,3,3 100,1,1
100,1,1 100,2,2 100,2,2 100,3,3 100,1,1
0,1,0 13,15,2