• Hello, im currently using this code to display the most commented on my blog, any way to make it display the most commented articles in just two weeks instead from begining?

    <?php
    $args = array(
    	'posts_per_page' => 5,
    	'orderby' => 'comment_count',
    	'order' => 'DESC'
    );
    	$recentposts = get_posts($args);
    		foreach ($recentposts as $post) :
    		setup_postdata($post);
    	?>
     <?php the_post_thumbnail(array(50,50), array ('class' => 'alignleft')); ?>
    	<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    	<?php endforeach; ?>

Viewing 1 replies (of 1 total)
  • Hello, this should do it:

    <?php
    function filter_posts($where = '') {
    		//posts in the last 14 days
    		$where .= " AND post_date > '" . date('Y-m-d', strtotime('-14 days')) . "'";
    		return $where;
    }
    
    add_filter('posts_where', 'filter_posts');
    
    $args = array(
    	'posts_per_page' => 5,
    	'orderby' => 'comment_count',
    	'order' => 'DESC'
    );
    
    $filter_posts_query = new WP_Query($args);
    remove_filter('posts_where', 'filter_posts');
    
    //loop for displaying posts
    while ($filter_posts_query->have_posts()) : $filter_posts_query->the_post();
    
    	the_post_thumbnail(array(50,50), array ('class' => 'alignleft'));
    ?>
    
    	<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    
    <?php endwhile; ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Displaying most commented in two weeks’ is closed to new replies.