Title: show random posts in this code
Last modified: August 20, 2016

---

# show random posts in this code

 *  [jack randall](https://wordpress.org/support/users/theotherlebowski/)
 * (@theotherlebowski)
 * [15 years ago](https://wordpress.org/support/topic/show-random-posts-in-this-code/)
 * hello, i was wondering if any code gurus out there might be able to help: i’ve
   got client who’s using a child of the Neptune theme on her site and she wants
   to have the recent posts sidebar doodah to show a random selction of posts (obviously
   i’ll need to rename the doodah!) rather than the top 6 newest posts.
 * this is the code that fetches and outputs:
 *     ```
       <ul>
       <?php
       	$my_query = new WP_Query('showposts=6');
       	while ($my_query->have_posts()) : $my_query->the_post();$do_not_duplicate = $post->ID;
       ?>
       <li>
   
       	<?php if ( has_post_thumbnail() ) {?>
       	<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>">
       	<?php  the_post_thumbnail( 'neptune-minithumb', array('class' => 'custim3') );?></a>
       	<?php } else { ?>
   
       	<?php } ?>
   
       </li>
   
       <?php endwhile; ?>
       </ul>
       ```
   
 * i know there’s a MySQL call for generating random results but my php coding chops
   aren’t up to the job i’m afraid. can anyone see where if at all i can make changes
   to this code to make it show the random selection?
 * the site in question is [hierophant-nox.com](http://hierophant-nox.xom) if you
   want to take a look see the end results.
 * big thanks in advance guys. 😀

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years ago](https://wordpress.org/support/topic/show-random-posts-in-this-code/#post-2092451)
 * [http://codex.wordpress.org/Function_Reference/WP_Query#Order_.26_Orderby_Parameters](http://codex.wordpress.org/Function_Reference/WP_Query#Order_.26_Orderby_Parameters)
 * example:
    `$my_query = new WP_Query('posts_per_page=6&orderby=rand');`
 *  Thread Starter [jack randall](https://wordpress.org/support/users/theotherlebowski/)
 * (@theotherlebowski)
 * [15 years ago](https://wordpress.org/support/topic/show-random-posts-in-this-code/#post-2092459)
 * you legend 😀 just the ticket. thanks dude.

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

The topic ‘show random posts in this code’ is closed to new replies.

## Tags

 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [php coding](https://wordpress.org/support/topic-tag/php-coding/)
 * [random posts](https://wordpress.org/support/topic-tag/random-posts/)

 * 2 replies
 * 2 participants
 * Last reply from: [jack randall](https://wordpress.org/support/users/theotherlebowski/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/show-random-posts-in-this-code/#post-2092459)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
