How to count the current posts terms WordPress

wp_count_terms the function counts terms in a given taxonomy (e.g. total number of categories, total number of tags).

To get what you want, get the terms for the post and just count them count( wp_get_post_terms( $post_id, $taxonomy, $args ) );. Or, assuming that in real life you might need those terms later:

$terms = wp_get_post_terms( $post_id, $taxonomy, $args );
$terms_count = count ( $terms );

count() function help you to count total terms.

Leave a Comment