1/14/2016 - 4:22 PM

How to exclude categories when using Display Posts Shortcode

February 4, 2014 by Sridhar Katakam

Then to exclude a single category for example, use this shortcode on a post or page:
[display-posts cat_not_in="30"]
view raw
gistfile1.txt hosted with ❤ by GitHub

to exclude multiple categories, use this sample shortcode:
[display-posts cat_not_in="30, 43"]

Bill Erickson’s Display Posts Shortcode plugin can be used to easily display a list of posts wherever shortcodes work. It does not have a built-in option to specify the IDs or slugs of categories if you wish to exclude any. But it can be extended using the display_posts_shortcode_args filter.

Add the code below in child theme’s functions.php to make available a cat_not_in parameter whose value will be the ID or comma separated IDs of categories you wish to be excluded from the listing:
//* Display Posts Shortcode - Exclude Categories

add_filter( 'display_posts_shortcode_args', 'be_display_posts_shortcode_exclude_categories', 10, 2 );
function be_display_posts_shortcode_exclude_categories( $args, $atts ) {

	if( isset( $atts['cat_not_in'] ) ) {
		$categories = explode( ',', $atts['cat_not_in'] );
		$args['category__not_in'] = $categories;

	return $args;