Title: Posts in Random Order
Last modified: August 20, 2016

---

# Posts in Random Order

 *  Resolved [zachmattheus](https://wordpress.org/support/users/zachmattheus/)
 * (@zachmattheus)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/)
 * How can I set the homepage to have a random order every time somebody visits 
   or refreshes my site [http://www.zachmattheus.com?](http://www.zachmattheus.com?)

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641839)
 * See [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 *  Thread Starter [zachmattheus](https://wordpress.org/support/users/zachmattheus/)
 * (@zachmattheus)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641843)
 * Sorry I’m not very good with code… you mean here?
 *     ```
       <?php
             $args = array(
                          'category_name' => 'featured small',
                          'post_type' => 'post',
                          'posts_per_page' => 30,
                          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
                          );
             query_posts($args);
             $x = 0;
             while (have_posts()) : the_post(); ?>
   
               <?php if($x == 0) { ?>
               <div class="featured_box first">
               <?php } elseif($x == 2) { ?>
               <div class="featured_box last">
               <?php } else { ?>
               <div class="featured_box">
               <?php } ?>
       ```
   
 * _[Moderator Note: Please post code or markup snippets between backticks or use
   the code button.]_
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641845)
 * Well that’s a custom query, yes but it’s not going to create a random order.
 *  Thread Starter [zachmattheus](https://wordpress.org/support/users/zachmattheus/)
 * (@zachmattheus)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641861)
 * Ahhh, that’s the code I’m using at the moment provided by the theme
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641862)
 * In that case, try replacing the query parameters with:
 *     ```
       $args = array(
       	'category_name' => 'featured small',
       	'post_type' => 'post',
       	'posts_per_page' => 30,
       	'orderby' => 'rand',
       	'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
       	);
       ```
   
 *  Thread Starter [zachmattheus](https://wordpress.org/support/users/zachmattheus/)
 * (@zachmattheus)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641879)
 * Tried but nope.
 *     ```
       <?php
             $args = array(
                          'category_name' => 'featured small',
                          'post_type' => 'post',
                          'posts_per_page' => 30,
                          'orderby' => 'rand',
                          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
                          );
             query_posts($args);
             $x = 0;
             while (have_posts()) : the_post(); ?>
   
               <?php if($x == 0) { ?>
               <div class="featured_box first">
               <?php } elseif($x == 2) { ?>
               <div class="featured_box last">
               <?php } else { ?>
               <div class="featured_box">
               <?php } ?>
       ```
   
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641881)
 * That should work but right now, it seems your site is down.
 *  Thread Starter [zachmattheus](https://wordpress.org/support/users/zachmattheus/)
 * (@zachmattheus)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641886)
 * It was that code that did that. Fixed by deleting `orderby' => 'rand',`
 *  Thread Starter [zachmattheus](https://wordpress.org/support/users/zachmattheus/)
 * (@zachmattheus)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641899)
 * all fixed!

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

The topic ‘Posts in Random Order’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 2 participants
 * Last reply from: [zachmattheus](https://wordpress.org/support/users/zachmattheus/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/posts-in-random-order-1/#post-2641899)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
