Hi,
Please use this code to exclude subcategories from the loop in wordpress blog. Just need to ad this code in either functions.php file or set a plugin and activate it..
if ( !function_exists(‘fb_filter_child_cats’) ) {
function fb_filter_child_cats( $cats )
{
global $wp_query, $wpdb;
if ( is_category() )
{
if ( $excludes = get_categories( “child_of=” . $wp_query->get(‘cat’) ) )
{
foreach ( $excludes as $key => $value )
{
$exclude[] = $value->cat_ID;
}
}
if ( isset($exclude) && is_array($exclude) )
{
$cats .= ” AND ” . $wpdb->prefix . “term_taxonomy.term_id NOT IN (” . implode(“,”, $exclude) . “) “;
}
}
return $cats;
}
if(!is_admin() )
{
add_filter( ‘posts_where’, ‘fb_filter_child_cats’ );
}
}
Thanks,
Shane G.
Popularity: 4%