Skip to content

Instantly share code, notes, and snippets.

@Restoration
Created October 27, 2016 11:13
Show Gist options
  • Select an option

  • Save Restoration/b8a906759bceeca21a3cafd2301f4f08 to your computer and use it in GitHub Desktop.

Select an option

Save Restoration/b8a906759bceeca21a3cafd2301f4f08 to your computer and use it in GitHub Desktop.
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>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment