有没有办法从自定义分类法中统计所有已发布的帖子?
环顾四周,我发现this snippet 但我没能成功…
global $wpdb;
$query = "
SELECT COUNT( DISTINCT cat_posts.ID ) AS post_count
FROM wp_term_taxonomy AS cat_term_taxonomy INNER JOIN wp_terms AS cat_terms ON
cat_term_taxonomy.term_id = cat_terms.term_id
INNER JOIN wp_term_relationships AS cat_term_relationships
ON cat_term_taxonomy.term_taxonomy_id = cat_term_relationships.term_taxonomy_id
INNER JOIN wp_posts AS cat_posts
ON cat_term_relationships.object_id = cat_posts.ID
WHERE cat_posts.post_status = \'publish\'
AND cat_posts.post_type = \'post\'
AND cat_term_taxonomy.taxonomy = \'YOUR-CUSTOM-TAXONOMY\'
AND cat_terms.slug IN (\'TERM-SLUG-1, TERM-SLUG-2\')
";
return $wpdb->get_var($query);