Hide Empty Taxonomy
-
Hello, I am using the below code to display taxonomies on a page template. The taxonomies are displaying, but they are not hiding the empty terms (no content associated with the taxonomy). Any ideas on how to hide empty terms with the below code, or even a different code? Thanks
<?php $args = array( 'hide_empty=1', 'hierarchical=1' ); $terms = get_terms( 'service-area', $args ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { $count = count( $terms ); $i = 0; $term_list = '<p class="my_term-archive">'; foreach ( $terms as $term ) { $i++; $term_list .= '<a href="' . esc_url( get_term_link( $term ) ) . '" alt="' . esc_attr( sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) ) . '">' . $term->name . '</a>'; if ( $count != $i ) { $term_list .= ', '; } else { $term_list .= '</p>'; } } echo $term_list; } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Hide Empty Taxonomy’ is closed to new replies.