Title: Exclude Current Post from Query
Last modified: August 30, 2016

---

# Exclude Current Post from Query

 *  [cgriffis](https://wordpress.org/support/users/cgriffis/)
 * (@cgriffis)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/exclude-current-post-from-query-1/)
 * I have a sidebar that is pulling in related blog posts by tags but it is showing
   the current post in the sidebar instead of just pulling two random posts.
 * Sample page: [http://staging.rswcreative.com/four-signs-that-mobile-learning-is-on-the-rise/](http://staging.rswcreative.com/four-signs-that-mobile-learning-is-on-the-rise/)
 * This is the code that I think needs to be edited.
 *     ```
       <aside id="news-entry-sidebar">
                  <div id="related-case-header">Related Case Studies</div>
       		<?php
       		$posttags = get_the_tags();
       		$test = '';
       		$sep = '';
       		if ($posttags) {
       			foreach($posttags as $tag) {
       				$test .= $sep . $tag->name;
       				$sep = ",";
       			}
       		}
       		query_posts('tag=' .$test . '&showposts=1'); while (have_posts()) : the_post(); ?>
       		<div class="post-page-work-entry">
       			<?php the_post_thumbnail(); ?>
       			<p style="line-height: 110%;"><?php the_field('client'); ?><br />
       			<?php the_title(); ?><br />
       			<span style="color: #888888; font-size: 16px;"><?php the_field('project_type'); ?></span></p>
       			<p class="post-page-work-entry-excerpt"><?php the_excerpt(); ?><a href="<?php the_permalink(); ?>"></a></p>
       		</div>
   
       		<?php endwhile; wp_reset_query(); ?>
   
               </aside>
       ```
   

The topic ‘Exclude Current Post from Query’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)

 * 0 replies
 * 1 participant
 * Last reply from: [cgriffis](https://wordpress.org/support/users/cgriffis/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/exclude-current-post-from-query-1/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
