Title: Random Posts, Multiple Queries
Last modified: August 19, 2016

---

# Random Posts, Multiple Queries

 *  Resolved [misterpatrick67](https://wordpress.org/support/users/misterpatrick67/)
 * (@misterpatrick67)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/random-posts-multiple-queries/)
 * Hi all,
 * forgive the probably basic question, but I am new to WordPress and am slowly 
   getting used to the code. Plus, I’m not a coder but a designer so everything 
   takes a bit longer for me. I’d like to display a list of four random posts in
   a sidebar. The code I am using is working fine, but it is displaying all of the
   posts and I’d like to limit it to four. The tricky part is that because I am 
   displaying each in a rounded-corner box, I need different queries.
 * The following works fine but is showing all of the posts and it is all in one
   box.
 *     ```
       <div class="victories">
         <div class="roundedcornr_top"><div></div></div>
         <div class="roundedcornr_content">
            <?php query_posts('cat=4'. '&orderby=rand'); ?>
               <?php while (have_posts()) : the_post(); ?>
                  <h1><?php the_title(); ?></h1>
               <?php the_content(); ?>
              <?php endwhile;?>
       </div>
       <div class="roundedcornr_bottom"><div></div></div>
       </div>
       ```
   
 * This works fine, but if I put this in each box, I get a random post, but the 
   same random post in each box.
 *     ```
       <div class="victories">
         <div class="roundedcornr_top"><div></div></div>
         <div class="roundedcornr_content">
            <?php query_posts('cat=4'. '&orderby=rand'); ?>
              <h1><?php the_title(); ?></h1>
            <?php the_content(); ?>
       </div>
        <div class="roundedcornr_bottom"><div></div></div>
       </div>
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [misterpatrick67](https://wordpress.org/support/users/misterpatrick67/)
 * (@misterpatrick67)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/random-posts-multiple-queries/#post-1032111)
 * OK, figured it out. It’s simply adding a &showpost=1.

Viewing 1 replies (of 1 total)

The topic ‘Random Posts, Multiple Queries’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [misterpatrick67](https://wordpress.org/support/users/misterpatrick67/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/random-posts-multiple-queries/#post-1032111)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
