[Plugin: Post Category Only] Show category on main
-
I’ve been wondering if there’s any way to use this awesome plugin to show just posts from one category on my Home page.
I’ve been using this workaround to show them, but it shows child categories too.
function exclude_category($query) { if ( $query->is_home ) { $query->set('cat', '7'); } return $query; } add_filter('pre_get_posts', 'exclude_category');
and here’s the original ‘Post category only’ plugin:
class post_category_only { static function load() { add_action('pre_get_posts', array('post_category_only', 'pre_get_posts')); } static function pre_get_posts($argument) { if($argument->is_category) { $category = get_category_by_path($argument->query['category_name']); if($category) { $argument->query_vars['category__in'] = $category->cat_ID; } } } } post_category_only::load();
Thanks for help!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘[Plugin: Post Category Only] Show category on main’ is closed to new replies.