removement
6/23/2019 - 5:42 PM

Exclude Current Post from WP Query

For example: having a related post block on a blog post detail page, make sure the post you are viewing does not show up in related posts

<?php
$currentID = get_the_ID();
$my_query = new WP_Query( array(
  'cat' => '1', 
  'showposts' => '5', 
  'post__not_in' => array($currentID)
));
while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title() ?></a></h2>
<?php the_content(); ?>
<?php endwhile; ?>