Title: Adding a random post
Last modified: August 19, 2016

---

# Adding a random post

 *  Resolved [eronkid](https://wordpress.org/support/users/eronkid/)
 * (@eronkid)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/adding-a-random-post/)
 * Hi there,
 * I am not a coder and I don’t have any above level skills in php. But I found 
   this piece of code for placing a specific category and it WORKS!
 * > <?php
   >  $featuredPosts = new WP_Query(); $featuredPosts->query(‘category_name
   > =featured&showposts=1’);
   > while($featuredPosts->have_posts()) :
   >  $featuredPosts->the_post();?>
   > </h3>
   >  <p><img src=”<?php echo get_post_meta($post->ID, ‘featurethumb’, true);?
   > >”/><?php the_excerpt(); ?></p> <p class=”readit”>“>Read more»</p>
   > <?php endwhile; ?>
 * Now my problem is, how can I make a random post from that specific category? 
   I guess a small insertion of code, something like that. Thank you very much for
   taking some time regarding my problem.

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/adding-a-random-post/#post-1245699)
 * This should work:
 *     ```
       $featuredPosts->query('category_name=featured&showposts=1&orderby=rand');
       ```
   
 *  Thread Starter [eronkid](https://wordpress.org/support/users/eronkid/)
 * (@eronkid)
 * [16 years, 7 months ago](https://wordpress.org/support/topic/adding-a-random-post/#post-1245706)
 * Thank you MichaelH!
    Yes, it really works fine.

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

The topic ‘Adding a random post’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [specific](https://wordpress.org/support/topic-tag/specific/)

 * 2 replies
 * 2 participants
 * Last reply from: [eronkid](https://wordpress.org/support/users/eronkid/)
 * Last activity: [16 years, 7 months ago](https://wordpress.org/support/topic/adding-a-random-post/#post-1245706)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
