WordPress.org

Ready to get started?Download WordPress

Forums

Taxonomy Terms List
Show Count possible with get_the_term_list? (4 posts)

  1. iftomkins
    Member
    Posted 3 years ago #

    Is it possible to show the count beside each taxonomy term? I've been trying hard to modify the plugin code to show the count, and even use the get_the_term_list function directly, but I can't figure it out. I'm wondering if it might not be possible to show the term count as long as we're using the get_the_term_list and get_term function? If this is the case, then this would stop another search of mine, from a previous forum post, where I'm looking to restrict the terms to those with a count > 1.

    Is this the case, does anyone know?

    http://wordpress.org/extend/plugins/taxonomy-terms-list/

  2. Michael Fields
    Themer
    Plugin Author

    Posted 3 years ago #

    I don't believe that get_the_term_list() allows you to display count.

    Heres one way of doing it:

    $term = get_term_by( 'slug', 'term_slug', 'taxonomy_slug' );
    print $term->count;

    Basically, anytime you have a term object at your disposal, you can use the count property.

    Something important to mention: Currently, it is not really a good idea to rely on term->count to determine whether or not you should display posts. I have received reports from users of my Taxonomy List Shortcode that the terms will display with a count of one even if there are no published post associated with the term... if the post is a draft.

    Here are a few trac tickets that seem to report the same type of issue:

    http://core.trac.wordpress.org/ticket/14392
    http://core.trac.wordpress.org/ticket/14084
    http://core.trac.wordpress.org/ticket/14073

  3. iftomkins
    Member
    Posted 3 years ago #

    Very good to know. I can't seem to figure out how to get the terms only for that particular post (replicating the Terms List Plugin but in the page template). Is this something that can be done? Honestly, I was hoping to cut and paste something into your plugin code that would let me show the count. But I'm thinking I would have to replicate the plugin actions, but for get_terms_by instead of get_the_term_list?

  4. Michael Fields
    Themer
    Plugin Author

    Posted 3 years ago #

    You might want to try get_object_terms().

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic