• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » Snippets » WordPress Snippets » Most Commented WordPress Posts in the last 30 days

Most Commented WordPress Posts in the last 30 days

Posted on July 10, 2012 by Renji | Short URL: http://sumtips.com/?p=7163

This code will return an unordered list of most commented WordPress posts in the last 30 days. You can easily customize it as per your preference.

<ul>
<?php
function filter_where($where = '') {

$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}

add_filter('posts_where', 'filter_where');

query_posts('post_type=post&posts_per_page=5&orderby=comment_count&order=DESC');

while ( have_posts() ): the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php

endwhile;
wp_reset_query();
remove_filter( 'posts_where', 'filter_where' );
?>
</ul>

Tweet

Related posts:

  • Automatically Add Attributes to All Images in WordPress Posts
  • Add Signature to WordPress Posts without Installing a Plugin
  • Add Pages, Custom Post Types in WordPress Site Feed
  • Add IE9′s Pinning Feature on WordPress, Show Recent Posts, Categories, More
  • Delete All Pingback and Trackback Comments from WordPress Posts
Categories: WordPress Snippets
Delete All Pingback and Trackback Comments from WordPress Posts
Disable WordPress Comment Form User Details Cookie

  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Offline Install .NET Framework 3.5 on Windows 8 & Windows Server 2012
    • WordPress: Add Preview Button in Distraction Free Writing
    • Completely Uninstall iTunes from Windows
    • Schedule Google Analytics to Email Website Performance Report
    • Set a Doodle as Your Permanent Google Icon
    • Host Personal Web-Based Feed Reader on Your Server
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy