Title: Random posts in archive.php?
Last modified: August 20, 2016

---

# Random posts in archive.php?

 *  [Pete](https://wordpress.org/support/users/perthmetro/)
 * (@perthmetro)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/random-posts-in-archivephp/)
 * I’ve got this in my archive.php… but how do i randomise the posts?
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       <?php the_title();?>
       <?php endwhile; else: ?>
       ```
   
 * Thanks heaps!!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/random-posts-in-archivephp/#post-2910498)
 * Try changing this:
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       ```
   
 * to this:
 *     ```
       <?php global $query_string;
       query_posts($query_string . '&orderby=rand');
       if (have_posts()) : while (have_posts()) : the_post(); ?>
       ```
   
 * You should note that randomizing will interfere with pagination. Pagination really
   doesn’t make sense with random retrieval.
 *  Thread Starter [Pete](https://wordpress.org/support/users/perthmetro/)
 * (@perthmetro)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/random-posts-in-archivephp/#post-2910502)
 * Thanks i’ll give it a go.
 *  Thread Starter [Pete](https://wordpress.org/support/users/perthmetro/)
 * (@perthmetro)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/random-posts-in-archivephp/#post-2910503)
 * This worked
 *     ```
       <?php $posts = query_posts($query_string . '&orderby=rand'); ?>
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Random posts in archive.php?’ is closed to new replies.

## Tags

 * [archive.php](https://wordpress.org/support/topic-tag/archive-php/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [rand](https://wordpress.org/support/topic-tag/rand/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Pete](https://wordpress.org/support/users/perthmetro/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/random-posts-in-archivephp/#post-2910503)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
