function get_ordered_terms( $id = 0, $orderby = 'slug', $order = 'ASC', $taxonomy = 'category' ) {
$terms = get_the_terms( $id, $taxonomy );
if ( $terms ) {
$ordered = array();
foreach ( $terms as $term ) {
if ( isset( $term->$orderby ) ) {
$ordered[$term->$orderby] = $term;
}
}
if ( strtoupper( $order ) == 'DESC' ) {
$func = 'krsort';
} else {
$func = 'ksort';
}
$func( $ordered );
return $ordered;
print_r($ordered);
}
}
function custom_the_category() {
$categories = get_ordered_terms();
foreach($categories as $category){
$url = get_category_link($category->term_id);
$name = $category->name;
echo "<a href='".$url."'>".$name."</a> ";
}
}
一度設定しちゃったcustom_the_category()が動かなくなったので強引な手段として・・・・。
記事が属しているカテゴリーを取得し、slugなどで並び替えて表示するってコードをかいていたけどいつの間にか動かなくなっていたので再度設置。
テンプレートのファンクションを変えるのは怖かったのでfuncitons.phpの記述を変更して対応。