$taxonomy = "category"; // can be category, post_tag, or custom taxonomy name // Use any one of the three methods below // Using Term ID $term_id = 1; $term = get_term_by('id', $term_id, $taxonomy); // Using Term Name $term_name = 'A Category'; $term = get_term_by('name', $term_name, $taxonomy); // Using Term Slug $term_slug = 'a-category'; $term = get_term_by('slug', $term_slug, $taxonomy); // Fetch the count echo $term->count; |
Get number of posts belonging to a particular category, tag or custom taxonomy.
Categories: .
Thanks, i was exactly looking for that! Works fantastic!
Kind regards,
Christian