How do I exclude recent post from recent post php widget
Question
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
<?php
$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() ?>
<li>
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( $size, $attr ); ?>
<?php endif ?>
</li>
<?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
0
exclude, get-posts, php, recent-posts
3 years
2020-04-02T12:51:12-05:00
2020-04-02T12:51:12-05:00 0 Answers
117 views
0
Leave an answer