Restoration
10/27/2016 - 11:13 AM

get_termsでカスタムタクソノミー一覧表示

get_termsでカスタムタクソノミー一覧表示

<?php
$taxonomy = 'product';
$args = array(
    'pad_counts' => true,
    'hide_empty' => false
);
$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;
        }
        if( $term->parent != 0 ) {
            echo '<li class="children">';
        } else {
            echo '<li>';
        }
        echo '<a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>(' . $term->count . ')';
        echo '</li>';
    }
echo '</ul>';
}
?>