How do I exclude recent post from recent post php widget


I have this code, and I tried adding in post__not_in as suggested by another post I found on this website, and it didn’t break anything but didn’t work either. I also tried different examples.

Here’s the php code I have

$args = array( 'posts_per_page' => '4', 'post__not_in' => array($currentID) );
$recent_posts = new WP_Query($args);
while( $recent_posts->have_posts() ) :  
    $recent_posts->the_post() ?>

        <?php if ( has_post_thumbnail() ) : ?>
            <?php the_post_thumbnail( $size, $attr ); ?>
        <?php endif ?> 

<?php endwhile; ?>
<?php wp_reset_postdata(); # reset post data so that other queries/loops work ?> 

It doesn’t get rid of the current post on the list

, , , sevenkader 3 years 2020-04-02T12:51:12-05:00 0 Answers 117 views 0

Leave an answer