Created
August 15, 2012 17:12
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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