Loop On Post Page Not Excluding Current Post
-
Hello,
I’m trying to have 3 post links show up that are related to the current posts by a custom taxonomy. The links show up just fine, but the loop won’t exclude the current post from the list. Any gurus out there know what I’m doing wrong?? I’ve been at this for hours, and can’t seem to figure it out. It’s probably so simple that I’m overlooking it. Or I suck, either one.
Here’s the code.
$TaxName = 'ad-agency';if (has_term( '', $TaxName, $post->ID )) {
$this_post = $post->ID;
foreach((get_the_terms($post->ID, $TaxName)) as $Term) {
$posts = new WP_Query( 'taxonomy='.$TaxName.'&term='.$Term->slug.'&posts_per_page=3&orderby=rand&exclude=' . $this_post );
if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post();
//the content
endwhile; endif;
wp_reset_postdata();
}
}
I have the code live and can provide a link if that helps.
- The topic ‘Loop On Post Page Not Excluding Current Post’ is closed to new replies.