我有一种奇怪的行为。我正在使用get_categorie函数读取帖子数量。但是对于某些类别,它显示了错误的数字。 示例类别XY(3)但它只有一个Post而不是三个。 总帖子数是正确的。谁知道问题可能是什么?提前致谢
if ( ! empty( $categories ) ) {
$categories_args['slug'] = explode( ',', $categories );
}
$filter_categories = get_categories( $categories_args );
$filter_html = '';
$filter = isset( $filter ) ? $filter : 'none';
if ( $filter == 'category' AND $type != 'carousel' ) {
// $categories_names already contains only the used categories
if ( count( $filter_categories ) > 1 AND $query_args['post_type'] == "post" ) {
$count_posts = wp_count_posts();
$published_posts = $count_posts->publish;
$classes .= ' with_filters';
$filter_html .= '<div class="g-filters ' . $filter_style . '"><div class="g-filters-list">';
$filter_html .= '<div class="g-filters-item active" data-category="*"><span>' . __( 'All', 'us' ) . '<span class="subText"> ('.$published_posts.')</span></span></div>';
foreach ( $filter_categories as $filter_category ) {
$filter_html .= '<div class="g-filters-item" data-category="' . $filter_category->slug . '"><span>' . $filter_category->name . '</span><span class="subText"> ('.$filter_category->count.')</span></div>';
}
$filter_html .= '</div></div>';
}
}