Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active May 14, 2019 19:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save srikat/8803569 to your computer and use it in GitHub Desktop.
Save srikat/8803569 to your computer and use it in GitHub Desktop.
Excluding categories when using Display Posts Shortcode. http://sridharkatakam.com/exclude-categories-using-display-posts-shortcode/
//* 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;
}
[display-posts cat_not_in="30"]
[display-posts cat_not_in="30, 43"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment