WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an argument for get_terms which I can fetch terms that only have say over 2 posts associated with it?
I have a terms page which lists all my terms for 'artists', the page is huge but a lot of these terms that only have one post so I would like to show only significant terms.

share|improve this question
up vote 2 down vote accepted


$terms = get_terms("my_taxonomy");
$count = count($terms);
if ( $count > 0 ){
    echo "<ul>";
    foreach ( $terms as $term ) {
        if ($term->count > 2) {
            echo "<li>" . $term->name . "</li>";
    echo "</ul>";

a shot. It will grab all the terms and then run a check to see if the $term->count is greater than 2 and if so, print out those terms.

share|improve this answer

This does basically the same as @Zach already added, but in a more smart/unreadable way :)

$taxons = get_terms(
         'hide_empty' => true // is the default
$count = count( $taxons );
$stack = array()
if ( 0 < $count)
    // Catch all terms that have a count of "1"
    // As we already have excluded all with 
    // a zero count are already excluded
    $to_exclude = wp_list_filter(
        ,array( 'count' => 1 )

    // fill our stack by filtering/diffing our 1-post taxons out
    $stack = array_diff( (array) $taxons, (array) $to_exclude )

echo '<pre>'.var_export( $stack, true ).'</pre>';
share|improve this answer
You and your damn crafty answers :) – Zach Oct 12 '12 at 19:52
@Zach Glad you answered - remembered me to upvote yours for "most readable" ;) - Btw: I haven't measured it, but I think with an iteration of 10k rounds involving timer_start()/*_stop(), yours will even be faster. – kaiser Oct 12 '12 at 19:59
Ah nice, always good to know – Zach Oct 12 '12 at 20:02
Hm I'm getting this error: Catchable fatal error: Object of class stdClass could not be converted to string – Imran Oct 12 '12 at 21:49
@Imran I'm pretty sure the problem is the objects inside the array, but please try it again and report back. In case, I'll rework it with an array_map another time. – kaiser Oct 12 '12 at 22:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.