i want to show some posts on a page, so when i using wp_query() as the following the next and the last doesn’t output any content, why?
<?php
$my_query = new WP_Query('showposts=1');
while ($my_query->have_posts()) : $my_query->the_post();
?>
<li>.....</li>
<?php endwhile; ?>
<?php
$query = new WP_Query( array( 'post__not_in' => get_option( 'sticky_posts' ) ) );
while ($query->have_posts()) : $query->the_post();
?>
<li>.....</li>
<?php endwhile; ?>
<?php
$query = new WP_Query( array ( 'orderby' => 'rand', 'posts_per_page' => '1' ) );
while ($query->have_posts()) : $query->the_post();
?>
<li>.....</li>
<?php endwhile; ?>
Because you went through the whole loop and there’s no post left. You need to execute
wp_reset_postdata()
.From the codex:
You need to reset post data after each query (right after
endwhile
):