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.

My page has three separate loops on it. The first retrieves the most commented post. The query then resets for the second loop and retrieves the 3 most recent posts, then resets again to get the three most recents posts after that. What I want is for the post that has the most comments to a) only be chosen from the last 24 hours and b) to be excluded from showing up in the 2nd and 3rd queries to prevent duplicate posts showing up.

How would I achieve this?

 <?php get_header(); ?>

            <div class="container_12 clearfix">

                <div class="grid_8 main-content">

                        <div class="grid_12 alpha omega">

                        <?php 

                        $args = array(
                        'posts_per_page' => 1,
                        'orderby' => 'comment_count'


                        );

                        $the_query = new WP_Query( $args );

                        ?>

                        <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

                            <a href="<?php the_permalink();?>"><h1 class="main-heading"><?php the_title(); ?></h1></a>
                            <p class="meta">Published on <?php the_date(); ?> by <a href="<?php echo the_permalink();?>"><?php the_author(); ?></a><a href="<?php the_permalink();?>"> <?php comments_number(); ?></a></p>

                            <?php the_excerpt(); ?>

                        <?php endwhile; else: ?>


                        <?php endif; ?>

                        <?php wp_reset_postdata(); ?>

                        </div>


                        <?php 

                        $args = array(
                        'posts_per_page' => 3,
                        'orderby' => 'most_recent'
                        );

                        $the_query = new WP_Query( $args );

                        ?>

                        <div class="grid_6 alpha">

                        <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

                            <a href="<?php the_permalink();?>"><h2><?php the_title(); ?></h2></a>
                            <p class="meta">Published on <?php the_date(); ?> by <a href="<?php echo the_permalink();?>"><?php the_author(); ?></p></a>
                            <?php the_excerpt(); ?>

                        <?php endwhile; else: ?>

                        <?php endif; ?>



                        <?php wp_reset_postdata(); ?>



                        </div>

                        <?php 

                        $exclude = $most_recent;


                        $args = array(
                        'posts_per_page' => 3,
                        'orderby' => 'most_recent',
                        'offset'  => 3
                        );

                        $the_query = new WP_Query( $args );

                        ?>

                        <div class="grid_6 alpha">

                        <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

                            <a href="<?php the_permalink();?>"><h2><?php the_title(); ?></h2></a>
                            <p class="meta">Published on <?php the_date(); ?> by <a href="<?php echo the_permalink();?>"><?php the_author(); ?></p></a>
                            <?php the_excerpt(); ?>

                        <?php endwhile; else: ?>

                        <?php endif; ?>

                        <?php wp_reset_postdata(); ?>

                        </div>

                </div><!--maincontent-->

                        <?php get_sidebar(); ?>

            </div><!--endcontainer-->

    <?php get_footer(); ?>
share|improve this question
    
start here: date_query and post__not_in. –  Milo Mar 19 at 1:21
    

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.