WordPress.org

Forums

WordPress Popular Posts
[resolved] [Plugin: WordPress Popular Posts] popular by day posts published (6 posts)

  1. botakedan
    Member
    Posted 2 years ago #

    Hi Hector,

    Is there a way to show popular based on day(s) the posts published?

    http://wordpress.org/extend/plugins/wordpress-popular-posts/

  2. Hector Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    Hi there,

    At the moment, no. WordPress Popular Posts lists all posts that have been viewed or commented in the selected time range - it doesn't matter when they were first published.

    However, you could change the plugin's code to limit the popular lists only to those posts published within the specified time range. For that, you need to change this:

    $query = "SELECT p.ID AS 'id', p.post_title AS 'title', p.post_date AS 'date', p.post_author AS 'uid' {$fields} FROM {$wpdb->posts} p {$join} WHERE p.post_status = 'publish' AND p.post_password = '' {$where} GROUP BY p.ID {$having} ORDER BY {$orderby} DESC LIMIT " . $instance['limit'] . ";";

    ...into this:

    $post_interval = "";
    
    if ($instance['range'] == "daily") {
    	$post_interval = " AND post_date_gmt > DATE_SUB('".$this->now()."', INTERVAL 1 DAY) ";
    } else if ($instance['range'] == "weekly") {
    	$post_interval = " AND post_date_gmt > DATE_SUB('".$this->now()."', INTERVAL 1 WEEK) ";
    } else if ($instance['range'] == "monthly") {
    	$post_interval = " AND post_date_gmt > DATE_SUB('".$this->now()."', INTERVAL 1 MONTH) ";
    }
    
    $query = "SELECT p.ID AS 'id', p.post_title AS 'title', p.post_date AS 'date', p.post_author AS 'uid' {$fields} FROM {$wpdb->posts} p {$join} WHERE p.post_status = 'publish' AND p.post_password = '' {$where} {$post_interval} GROUP BY p.ID {$having} ORDER BY {$orderby} DESC LIMIT " . $instance['limit'] . ";";

    And save changes.

    Please note that I didn't test the code as I'm a bit busy now, so you'll have to do it yourself. Also, you'll need to add this change each time the plugin gets updated and probably change a few things as this code might be obsolete in future releases.

  3. botakedan
    Member
    Posted 2 years ago #

    awesome...
    will try this right away...

  4. botakedan
    Member
    Posted 2 years ago #

    great, its works!!!
    may be you can add this on the next update :)

    thank you man...

  5. medraka
    Member
    Posted 2 years ago #

    Any chances for implementing this in recent version of plugin?

  6. Hector Cabrera
    Member
    Plugin Author

    Posted 2 years ago #

    Hi medraka,

    Yes, it's already on the ToDo list (see issue).

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WordPress Popular Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic