WordPress.org

Ready to get started?Download WordPress

Forums

faster way to show random post (2 posts)

  1. navjottomer
    Member
    Posted 3 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
    Member
    Posted 3 years ago #

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

    <ul>
    <li><h2>A random selection of my writing</h2>
    
    <ul>
     <?php
     $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