在Wordpress中,如果父类别为空,则它将重定向到其非空的第一个子类别。
答案 0 :(得分:2)
尝试这个
$category = get_queried_object();
$count_post = $category->count;
if($count_post==0)
{
$args=array(
'child_of' => $cat-id,
'hide_empty' => 1,
'orderby' => 'id',
'order' => 'ASC',
'depth' => '1'
);
$categories=get_categories($args);
$cat_link;
foreach($categories as $category) {
$cat_link=get_category_link( $category->term_id );
break;
}
wp_redirect( $cat_link );
}