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 a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

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

Let's Talk