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(); ?> 
  • 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

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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