• 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)
  • 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.