Site logo

[Support request] Custom taxonomy category count

Home Forums Support [Support request] Custom taxonomy category count

Home Forums Support Custom taxonomy category count

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2439907
    Jan

    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

    #2440054
    Ying
    Staff
    Customer Support

    Hi there,

    get_the_category() is for the categorytaxonomy, if it’s a custom taxonomy, try get_the_terms() instead.

    For more info: https://developer.wordpress.org/reference/functions/get_the_terms/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.