[How To] Exclude Current Posts from 2nd loop
-
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:
<?php 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; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘[How To] Exclude Current Posts from 2nd loop’ is closed to new replies.