Skip to content

Instantly share code, notes, and snippets.

@QROkes
Created March 18, 2016 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save QROkes/392c1d2ae467a6253b8a to your computer and use it in GitHub Desktop.
Save QROkes/392c1d2ae467a6253b8a to your computer and use it in GitHub Desktop.
List custom taxonomy terms (WordPress)
<?php
$args = array( 'hide_empty=0' );
$terms = get_terms( 'my-taxonomy', $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$count = count( $terms );
$i = 0;
$term_list = '<p class="term-list">Tags: ';
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 .= ' &middot; ';
}
else {
$term_list .= '</p>';
}
}
echo $term_list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment