How to display the number of published posts of any type in the current taxonomy, also custom? With taxonomy checking, that is, there should be one code for everyone.

I understand what and how it should work, but I can not write myself. According to the directory :

$count_posts = wp_count_posts('post'); $published_posts = $count_posts->publish; 

gets the number of published posts of a given type of 'post' in all categories. and More from the Internet :

 echo get_category($ID)->category_count; 

displays the number of published posts in a category; in theory, something like echo get_taxonomy($name)->category_count; should have worked echo get_taxonomy($name)->category_count; , but no

    1 answer 1

    How to display the number of published posts of any type in the current taxonomy, also custom?

    wp_count_terms or get_terms or wp_count_posts .

    gets the number of published posts of a given type of 'post' in all categories.

    It is necessary to transfer values:

    $published_posts = wp_count_posts('new_post_type')->publish;

    • this code will display the number of ALL published records. How to leave only those entries that are in the current category? - malginovdesign
    • hmm .. yes Looks like wp-kama.ru/function/get_term helps - SeVlad
    • can you write what the final version will look like? - malginovdesign