Title: Displaying Posts in random order
Last modified: August 20, 2016

---

# Displaying Posts in random order

 *  [suddensway](https://wordpress.org/support/users/suddensway/)
 * (@suddensway)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/displaying-posts-in-random-order/)
 * hi there,
 * I wish to display category posts in a random order for all category id’s except
   one which I’d like in the default order.
 * I’d rather not use a plug in – not than I can find one that does this anyway.
   I’m sure there’s a bit of php coding I can add/edit that someone out there with
   a bigger brain than me knows about!
 * If someone could help me with this I’d be a very happy bunny and most grateful…
 * I’m using Minimal from Elegant Themes and the site is at [http://www.allegroartslivemusic.co.uk/](http://www.allegroartslivemusic.co.uk/)
 * many thanks
    Kevin

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

 *  [bioshox](https://wordpress.org/support/users/bioshox/)
 * (@bioshox)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/displaying-posts-in-random-order/#post-2897467)
 * Hi
 * You could use
 *     ```
       <?php query_posts('category=whatever&showposts=5&offset=0&orderby=rand'); ?>
       ```
   
 * and that should work.
 *  Thread Starter [suddensway](https://wordpress.org/support/users/suddensway/)
 * (@suddensway)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/displaying-posts-in-random-order/#post-2897499)
 * Thanks for getting back to me bioshox but I’m not a developer at all and don’t
   really know how to implement this.
 * I found a chunk of code in the blog page template that included the query_posts
   phrase but it was this:
 *     ```
       <?php $cat_query = '';
       						if ( !empty($blog_cats) ) $cat_query = '&cat=' . implode(",", $blog_cats);
       						else echo '<!-- blog category is not selected -->'; ?>
       						<?php
       							$et_paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
       						?>
       						<?php query_posts("showposts=$et_ptemplate_blog_perpage&paged=" . $et_paged . $cat_query); ?>
       						<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       ```
   
 * Can you advise on how I could incorporate your suggestion into this at all?
 * To confirm, I want the posts to display in random order for posts in all categories
   except one (and there are many!) so was looking to use the conditional tag such
   as `!in_category( '14' )`
 * Does that make sense?
 * many thanks again for your help
    Kevin
 *  [bioshox](https://wordpress.org/support/users/bioshox/)
 * (@bioshox)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/displaying-posts-in-random-order/#post-2897505)
 * Hi Kevin,
 * try the following
 *     ```
       <?php $cat_query = '';
       						if ( !empty($blog_cats) ) $cat_query = '&cat=' . implode(",", $blog_cats);
       						else echo '<!-- blog category is not selected -->'; ?>
       						<?php
       							$et_paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
       						?>
       						<?php query_posts("showposts=$et_ptemplate_blog_perpage&paged=" . $et_paged . $cat_query."&orderby=rand"; ?>
       						<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       ```
   
 *  Thread Starter [suddensway](https://wordpress.org/support/users/suddensway/)
 * (@suddensway)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/displaying-posts-in-random-order/#post-2897514)
 * Hi bioshox
 * I’m afraid that didn’t work – posts are still being displayed by date rather 
   than randomly.
 * have you any other ideas on this at all?
 * many thanks
    Kevin
 *  [bioshox](https://wordpress.org/support/users/bioshox/)
 * (@bioshox)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/displaying-posts-in-random-order/#post-2897515)
 * Strange.
 * You may need to change your loop, this thread may be of use:
 * [http://wordpress.org/support/topic/recent-posts-random-order?replies=6](http://wordpress.org/support/topic/recent-posts-random-order?replies=6)

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

The topic ‘Displaying Posts in random order’ is closed to new replies.

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

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
