[How To] Exclude Current Posts from 2nd loop (3 posts)

  1. westondeboer
    Posted 6 years ago #

    I am pulling 5 random posts and i didn't want it to show the current post in this loop, so here is how to do it:

    global $wp_query;
    $thePostID = $wp_query->post->ID;
    $rand_posts = get_posts('numberposts=5&exclude='.$thePostID.'&orderby=rand');
     foreach( $rand_posts as $post ) :?>
    <h3><?php the_title(); ?></h3>
     <?php endforeach; ?>
  2. enailor
    Posted 6 years ago #

    Let's say I want to have 2 loops... the first one displays the most recent 5 posts, the second a random selection of posts; however I want the most recent 5 to be excluded from the second loop. How would you go about doing that?

  3. Dunkkan
    Posted 5 years ago #

    Hey, excellent ! Thanks very much for this.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.