I am using Wordpress 3.6. I would like to exclude posts on any given current page from appearing in the recent posts sidebar widget. I haven't been able to find a custom widget that has that option. I hope someone can help.
1 Answer
Add this to the functions.php theme (or child theme) file.
add_filter( 'widget_posts_args', 'wpse_109484_recent_post_count' );
function wpse_109484_recent_post_count( $args ) {
global $wp_query;
$excluded_posts = array();
foreach ( (array) $wp_query->posts as $post ) {
$excluded_posts[] = $post->ID;
}
$args['post__not_in'] = $excluded_posts;
return $args;
}
'widget_posts_args'
WordPress filter to add an array of excluded posts to the widget query.