Im using this widget.

but im trying to figure out how to get it to not display any posts that are currently being

displayed on the home page, single post and categories.

Another user raised the same question here

Which provided the following solution:

add_filter( 'rpwe_default_query_arguments', 'rpwe_exclude_current_post' );
function rpwe_exclude_current_post( $args ) {
if( is_singular() && !isset( $args['post__in'] ) )
$args['post__not_in'] = array( get_the_ID() );
return $args;

It worked but for single posts only not for posts in home page or categories.

  • 1
    Welcome to WPSE. Please note that specific support for third party plugins are off topic here. Your question does borderline this, but can still be answered in a general scope of Wordpress. Please keep the above in mind in future :-). You should check out How to Ask and help center to learn what type of questions are good questions and which ones aren't and also see what is considered in and out of scope. While you're at it, feel free to take a tour to learn how this site and other SE sites operate. Thank you :-) May 2, 2015 at 4:37
  • Remove this is_singular() && May 2, 2015 at 14:36

1 Answer 1


Specific support for third party plugins are off topic, but your question can be answered in a general scope. get_the_ID() will not work for this specific issue, what you need is an array of post ID's that is currently being displayed on the page you are viewing.

The current array of posts that is being displayed on any given page is stored in the $posts property of the main query or any custom instance of WP_Query. It is from here that you would want to extract all the post ID's from to pass to $args['post__not_in'] in your code in question.

You can try the following in your code above

global $wp_query;
$post_ids = wp_list_pluck( $wp_query->posts, 'ID' );

Then you can feed $post_ids to $args['post__not_in']

$args['post__not_in'] = $post_ids;

You just need to pass the correct conditionals to target your specific pages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.