Title: Random posts
Last modified: August 19, 2016

---

# Random posts

 *  [photoshopx](https://wordpress.org/support/users/photoshopx/)
 * (@photoshopx)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/random-posts-5/)
 * I´m going mad trying to find a plugin or code to randomize post within specific
   tags or categories..
 * For exemple,
 * I have 3 posts: Number 1, Number 2, Number 3 under “Lucky Numbers´category”
 * And a link somewhere: “whats your lucky number today” – so when clicked, the 
   random code is able to retrieve a post within “Lucky Numbers´category” only.
 * If someone else know some plugins or wp/code for this, please let me know!

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/random-posts-5/#post-1403455)
 *     ```
       <?php
       $lucky_num = rand  ( 1 , 3  );
       $post_slug = 'Number '. $lucky_num;
       $args= array(
       	'category_name' => 'Lucky Numbers',
       	'name' => $post_slug,
       	posts_per_page = 1
       );
       query_posts($args);
       //The Loop
       if ( have_posts() ) : while ( have_posts() ) : the_post();
        ..
       endwhile; else:
        ..
       endif;
       ?>
       ```
   
 *  Thread Starter [photoshopx](https://wordpress.org/support/users/photoshopx/)
 * (@photoshopx)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/random-posts-5/#post-1403481)
 * **Thank you gonna try this!!**
 *  Thread Starter [photoshopx](https://wordpress.org/support/users/photoshopx/)
 * (@photoshopx)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/random-posts-5/#post-1403511)
 * Hello, your code works really nice, but that is for category.php/archive.php 
   files isn´t?!
 * In fact, I was looking for a plugin/code able to retrieve a random post within
   a specific category or tag. So whenever the visitors click the link, they will
   be send to a random post. I can´t find anything simple like that! Just a code
   for send visitor to a random link within a category/tag .
 * I solved this issue the worst I could figure out ( I think).
 * Using your code, I create categories just for show random posts and then I link
   the category in posts or pages.
 * So i have some 3 or 4 categories files for the post show up randomly.
 * Still, I want know if someone else know to solve that without creating categories
   files.

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

The topic ‘Random posts’ is closed to new replies.

 * 3 replies
 * 2 participants
 * Last reply from: [photoshopx](https://wordpress.org/support/users/photoshopx/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/random-posts-5/#post-1403511)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
