Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use this link to get most viewed posts:

http://mydomain.com/?post_type=movies&meta_key=post_views_count&orderby=meta_value&order=ASC

But that gives me ALL posts from this post type in order of the most viewed - but I'd like to have only the latest most viewed posts from that custom post type of e.g.. 30 days.

How could I handle this?

thank you!

AD

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Have you tried this plugin : WP Most Popular ?

You can display popular posts from the last day, 7 days, 30 days or all time.

From the "Other notes" page :

Usage

There are two ways in which you can use this plugin.

  1. As a sidebar widget
  2. Custom function in your theme files

Using the widget is the easiest way and recommended for most users. If you are a developer and want to integrate the plugin in to your existing theme, then read the information below.

Firstly, the main function which you will need to include in your theme to fetch the popular posts is called wmp_get_popular().

You can pass that function the following parameters in array form:

• limit (integer)
The number of posts you would like to display i.e. 5
Default: 5

• post_type (string)
The post type you would like to display
Example: post
Default: All post types

• range (string) In what date range would you like to display popular posts in
Accepted: all_time, monthly, weekly, daily
Default: all_time

Those are the current parameters that the plugin supports.

Let's look at an example of how to display the most recent popular posts in a unordered list :

<?php
echo '<ul>';
$posts = wmp_get_popular( array( 'limit' => 10, 'post_type' => 'post', 'range' => 'all_time' ) );
global $post;
if ( count( $posts ) > 0 ): foreach ( $posts as $post ):
    setup_postdata( $post );
    ?>
    <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
    <?php
endforeach; endif;
echo '</ul>';
?>
share|improve this answer

Your Answer

 
discard

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.