Site logo

Archived topic

Custom taxonomy category count

1 reply · Started by Jan on November 28, 2022

Viewing posts 1–2 of 2

Hi David,

in this threat you supported Nacho in a similar task.

In my case I'm using a custom taxonomy named wg_chat_categorywhich is linked to a CPT named wg_seo_chat.

How would you revise the following PHP:

function single_post_cat_link_with_count() {
    $category = get_the_category();
    $first_cat = $category[0];
    printf( 
        '<a class="button" href="%1$s" title="%2$s">%3$s <span class="cat-count">%4$s</span></a>',
        esc_url( get_category_link( $first_cat->cat_ID) ),
        esc_attr( $first_cat->cat_name ),
        esc_html( $first_cat->cat_name ),
        esc_html( $first_cat->category_count )
    );
}

...in order to achieve the result on the page below. Please note, that the numbers in brackets have been manually added.

Thanks in advance.

Best,
Jan

This archived topic is closed to new replies.