how to use wp_query three times in a page

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; ?>

Related posts

Leave a Reply

2 comments

  1. Because you went through the whole loop and there’s no post left. You need to execute wp_reset_postdata().

    From the codex:

    After looping through a separate query, this function restores the $post global 
    to the current post in the main query.