我不知道有什么直接的方法可以做到这一点,你应该可以使用get_term
然后从总数中减去。
function product_count_shortcode( $atts ) {
$data = shortcode_atts( array(
\'cat_id\' => 144,
\'taxonomy\' => \'category\'
), $atts );
$category = get_term( $data[\'cat_id\'], $data[\'taxonomy\'] );
$count = $category->count;
$count_posts = wp_count_posts( \'product\' );
return (int)$count_posts->publish - (int)$count;
}
add_shortcode( \'product_count\', \'product_count_shortcode\' );
发件人
iguanarama 答复:
您还可以使用WP_Query
$myQuery = new WP_Query ([
\'post_type\' => \'product\',
\'cat\' => \'-144\',
\'post_status\' => \'publish\'
]);
$count = ($myQuery ? $myQuery->found_posts : 0);