Display Posts Shortcode – Exclude Posts

The Display Posts Shortcode plugin lets you display posts based on many different parameters. One parameter that is missing is the ability to exclude certain posts from your listing. If you add this code to your theme’s functions.php file or core functionality plugin, you will be able to use [display_posts not_in="123,456"] where 123 and 456 are the IDs of posts you’d like excluded.

<?php
/**
* Display Posts Shortcode - Exclude Posts
* @author Bill Erickson
* @link http://wordpress.org/extend/plugins/display-posts-shortcode/
*
* @param array $args
* @param array $atts
* @return array $args
*/
function be_display_posts_shortcode_exclude_posts( $args, $atts ) {
if( isset( $atts['not_in'] ) ) {
$posts = explode( ',', $atts['not_in'] );
$args['post__not_in'] = $posts;
}
return $args;
}
add_filter( 'display_posts_shortcode_args', 'be_display_posts_shortcode_exclude_posts', 10, 2 );
view raw gistfile1.aw hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk