yuheijotaki.com

2016/07/27 : 
WordPress タームの一覧出力

◯テンプレートファイル

$taxonomy = 'TAXONOMY_NAME';
$args = array(
	'hide_empty' => true
);
$terms = get_terms( $taxonomy , $args );
if ( count( $terms ) != 0 ) {
	echo '<ul>';
	foreach ( $terms as $term ) {
		$term = sanitize_term( $term, $taxonomy );
		$term_link = get_term_link( $term, $taxonomy );
		if ( is_wp_error( $term_link ) ) {
			continue;
		}
		echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '(' . $term->count . ')</a></li>';
	}
	echo '</ul>';
}