The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

faster way to show random post (2 posts)

  1. navjottomer
    Posted 5 years ago #

    In my wordpress theme i have this code,

    <?php query_posts(array('post__in' => get_option('sticky_posts'), 'post_status' => 'publish', 'orderby' => 'rand')); ?>

    this is very slow, is there any faster way to do this.

  2. Tara
    Volunteer Moderator
    Posted 5 years ago #

    try this, add where you want show the random post:

    <li><h2>A random selection of my writing</h2>
     $rand_posts = get_posts('numberposts=5&orderby=rand');
     foreach( $rand_posts as $post ) :
    <li><a>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic