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 this simple snippets to get post view count for a long time I was wondering if we can add a "time" data ? Because I would like to show the view of yesterday/ 2 days ago / 2 days ago etc... ?

we can display in sidebar like MOST POPULAR POSTS OF THE DAY, MONTH or HOURS (if possible)

here is my sidebar code

 <?php query_posts('meta_key=post_views_count&orderby=meta_value_num&posts_per_page=4&order=DESC');    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
 <?php echo getPostViews(get_the_ID()); ?>            
<a class="tab_caption" href="<?php the_permalink(); ?>" title="<?php echo $post_title; ?>"><?php echo get_the_title($post->ID);?></a>  

<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?> 
share|improve this question
Well a nice. I suggest everyone to search the question before asking it. I was about to ask the same question. Many thanks looking forward for helpful replies. – user18670 Jul 29 '12 at 7:37
up vote 1 down vote accepted

Well, the code you are using to count views does store the count data as a custom_field value. If I want the functionality you mentioned in question, I'd rather use a custom plugin to create a separate table in database to store view count and respective dates. So doing some queries you can display popular posts by date/month etc.

share|improve this answer
thats ok amit this snipett author kevin say "wp_get_archives lets you define a short time period something like this I think would be useful. " codex.wordpress.org/Function_Reference/wp_get_archives i m bit confused – Nisha_at_Behance Aug 6 '12 at 7:11

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.