【Wordpress】タクソノミーの並び順を自由に設定する【プラグインなし】
やり方
1. functions.phpへ記述
functions.phpに以下を記述します。
add_filter( 'get_terms_orderby', 'taxonomy_orderby_description', 10, 2 ); function taxonomy_orderby_description( $orderby, $args ) { if ( $args['orderby'] == 'description' ) { $orderby = 'tt.description'; } return $orderby; }
2. 表示させたい箇所へ記述
get_terms('xxxx', 'orderby=description&order=ASC');
を記述します。
例)
$terms = get_terms('xxxx', 'orderby=description&order=ASC'); foreach ( $terms as $term ) { echo '<li><a href="?xxxx='.esc_html($term->slug).'">'.esc_html($term->name).'</a></li>'; }
こちらのフォーラムを参考にしました。 ja.wordpress.org