1

In a custom query, is there a way to show the first post twice? I want to show the first post in a certain format at the top of my query, then again right under it along with my other posts (maybe a little redundant). I've tried just pulling the post then showing it like, but when I call the_post it seems to remove it from my overall array of objects.

Simplified Version

<?php if($test->have_posts()) : $test->the_post(); ?>
    <h1><?php the_title(); ?></h1>
<?php endif; ?> 

<?php if($test->have_posts()) : ?>
    <?php while($test->have_posts()) : $test->the_post(); ?>
        <h3><?php the_title(); ?></h3>
    <?php endwhile; ?>
<?php endif; ?>

I've also tried to get into the array but I'm not sure how:

$post = $test->WP_Query[0];

How can I show my post, without 2 queries or modifying the original custom query?

1 Answer 1

4

Just rewind posts after the first post and run the loop again.

if($test->have_posts()) :
    $test->the_post();
    the_title();
endif;

$test->rewind_posts();

if($test->have_posts()) :
    while($test->have_posts()) :
        $test->the_post();
        the_title();
    endwhile;
endif;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.