• Hi guys. first, i lookup just in case to avoid asking but no luck.

    Im trying to get a specific taxonomy count.

    Im doing a dashboard that count taxonomies and custom post types. I manage to use wp_count_posts and wp_count_terms to get the counts and it works just fine. But now i want to get the number of specific term. I manage to query the whole list but now i just need to display a specific one.

    Im using $sgr_cpt = wp_count_terms('trabajo'); then echo it to get my count. Do i need to add something to the parm of the class? this is where i got stuck.

    thnx in advance. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Echoing the wp_count_terms('trabajo'); works fine on my end. It will return all terms you have for that taxonomy.

    I hope it will solve the issue. If not, please explain it to me a bit further.

    Best Regards,
    Calvin

    Thread Starter sugartoys

    (@sugartoys)

    Thnx Calvin.

    i think i didnt explain myself better because is the terms inside the taxonomy, but doesn’t matter now i figure it out, well i think hehe.

    1st to clarify this. I need to know the amount of post or count for a term. Lets say the taxonomy is Cars, then i want to know how many toyotas.

    I did make something work and i leave it here for reference or improvement (or fix if im doing wrong). Here a example of the concept i did.

    $sgr_count = array(
        'post_type' => 'car',
        'post_status' => 'published',
        'toyota' => 'gt86',
        'numberposts' => -1
    );
    echo $num = count( get_posts( $sgr_count ) );

    This bring me the count for gt86. ??

    Hey there sugartoys,

    How’s your weekend going so far? ??

    Well, I think the get_terms is the best function for your needs. You can do it like this:

    <?php
    	$args = array(
    			'slug'	=>	'tae', //slug of the term you want.
    			'fields' => 'count' //if this is set to 'all' it will return an array. if count it will return string
    		);
    
    	$terms = get_terms( 'trabajo', $args );
    
    	// since the 'fields' is set to 'count'. we can just echo it.
    	echo $terms;
    ?>

    Just don’t forget to change the taxonomy name(trabajo) and term name(tae) to your own.

    Hope it helps! ??

    Best Regards,
    Calvin

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Specific Taxonomy Count’ is closed to new replies.