Title: using rand
Last modified: August 19, 2016

---

# using rand

 *  [bg000331](https://wordpress.org/support/users/bg000331/)
 * (@bg000331)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/using-rand/)
 * hi,
    im trying to get a random hero image with
 * $hero_image = query_posts(array(‘post_type’=>’hero_image’, ‘orderby’=>’rand’,’
   posts_per_page’=>1));
 * the issue is that a lot of times on reload it uses the same random image. is 
   there
    a solution to make sure not the same image is getting used after page 
   refresh?
 * thanks
 * pete

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/using-rand/#post-1750575)
 * You might use the get_option() and update_option() functions to keep track of
   the last hero, something like this (UNTESTED):
 *     ```
       $args = array (
          'post_type' => 'hero_image',
          'orderby' => 'rand',
          'posts_per_page' => 1
       );
       $last = get_option('last-hero');
       if ($last) $args['post__not_in'] => array($last);
       $hero_image = query_posts($args);
       if ($hero_image) update_option('last-hero',$hero_image[0]->ID);
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘using rand’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/using-rand/#post-1750575)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
