Hi i'm trying to figure out how to count the number of terms for the current post, i've tried using wp_get_object_terms() and

$title = get_post($post->ID);
$numTerms = wp_count_terms( $title->post_type, array(
'hide_empty'=> false,
'parent'    => 0
) ); ?>

without any luck, does anyone have a solution for this issue?



wp_count_terms 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 );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.