Exclude current post from query loop


    <?php
        //Start current post loop
        if ( have_posts() ) while ( have_posts() ) : the_post();
           
            // Assign current post ID to a variable.
            $exclude_postID = $post->ID;
           
        endwhile; // end current post loop.
    ?>
    <?php
        $args = array(
            'post_type'=> array('post-type'),
            //'post__not_in' does the magic of excluding.
            'post__not_in' => array($exclude_postID),
        );
        query_posts( $args );
       
    ?>


*Remember to pass ‘$exclude_postID’ in an array.

Latest Comments

Leave a Reply

comment on this article