0

I'm using this code that will print out the ID for current post's terms.

foreach((get_the_terms($post->ID, 'project_category')) as $term) { 
echo $term->term_id. '';
}

Now i want to put this term id in this code.

$term = get_term( '7', 'category' ); 
$count = $term->count;
echo $count;

This code will print '2' as there are two posts in a category having term id 7. I want to replace '7' with the output from the upper code.

How can i do this?

0

If I'm understood, you want to run a loop and print the count for every term of your post. You can do so by this code:

foreach((get_the_terms($post->ID, 'project_category')) as $term) { 
    $term_object = get_term( $term->term_id, 'category' );
    echo $term_object->count;
}

Which will do what you asked for.

1
  • I want to print total number of posts in a particular category. Jun 30 '17 at 21:43

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.