Skip to content

Instantly share code, notes, and snippets.

@zvineyard
Created August 15, 2012 17:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zvineyard/3361675 to your computer and use it in GitHub Desktop.
Save zvineyard/3361675 to your computer and use it in GitHub Desktop.
WordPress: Exclude posts if they are only tagged in a single category (Plugin)
<?php
/*
Plugin Name: Exclude Posts if in Single Category
Description: Exclude posts if they are only tagged in a single category, as defined by the category number. This will show posts in the loop if they are tagged in more than one category.
Version: 1.0
Author: Zac Vineyard
Author URI: http://www.zacvineyard.com
*/
function exclude_category($query)
{
$categories = get_categories(array('exclude' => '46'));
if (!is_admin())
{
$query->set('cat', '-46');
$cat_ids = array();
foreach ($categories as $category) {
$cat_ids[] = $category->term_id;
}
$include = implode(",", (array) $cat_ids);
$query->set('cat', $include);
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment