0

I have this problem: I'm using get_terms with ordering by count. And some terms are missing - I have no idea why, there is no exlude, or hide posts or anything like this.

What is wrong? Here is the code:

<?php $terms = get_terms("autorzy", array('orderby' => 'count', 'order' => 'DESC'));
    $count = count($terms);
    if ( $count > 0 ){
    echo "<div>";
        foreach ( $terms as $term ) { ?>
<?php echo $term->name; ?>
<a href="<?php get_term_link( $term ); ?>" class="avatar-link"></a>
<?php echo term_description( $term->term_id, 'autorzy' ) ?>
    <?php } echo "</div>"; } ?>

EDIT: this term isn't empty, and that problem is only with orderby count. Now is set "name" and it shows:

http://wszystkoconajwazniejsze.pl/autorzy/ my problem is with the last one - Lemańska.

5
  • 1
    Do these missing terms have a count? Or are they zero? Is there more than one post type in the autorzy taxonomy? Can you show us a term thats missing in the backend? What happens if there's no term name/link/description? Perhaps the term is listed but the markup is empty? What if you use !is_wp_error( $terms ) instead of count? – Tom J Nowell Apr 1 '14 at 10:52
  • Count in these missing terms are more than zero, one is 13! Which is the most here. It's only one post type (post). There is the name, description - everything. In other "orderby" it shows... – Angie Apr 1 '14 at 10:56
  • Hook a filter onto terms_clauses and dump the vars the filter passes you, see if there's something that looks off in the data when you call get_terms with the count orderby vs without. – t31os Apr 1 '14 at 11:24
  • There's no lemanska term wszystkoconajwazniejsze.pl/autorzy/lemanska gives me a 404 ( as does the version with the accented n). I've also updated the WP Codex example your code appears to be based on to make use of empty() and is_wp_error() instead of count()` – Tom J Nowell Apr 1 '14 at 12:17
  • wszystkoconajwazniejsze.pl/autorzy/joanna-lemanska - it's like this. I just shorted in on writing. but it still doesn't tell anything, because it's not empty and in other order it shows. – Angie Apr 2 '14 at 6:56
1

By default hide_empty is true for get_terms. So i guess you must be missing terms which do not have posts. Try this,

<?php $terms = get_terms("autorzy", array('orderby' => 'count', 'order' => 'DESC','hide_empty'=>0 ));
    $count = count($terms);
    if ( $count > 0 ){
    echo "<div>";
        foreach ( $terms as $term ) { ?>
<?php echo $term->name; ?>
<a href="<?php get_term_link( $term ); ?>" class="avatar-link"></a>
<?php echo term_description( $term->term_id, 'autorzy' ) ?>
    <?php } echo "</div>"; } ?>
1
  • No, that term is not empty, that's my main problem. – Angie Apr 1 '14 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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