如何从get_term_children按字母顺序对id进行排序?

时间:2012-11-22 13:20:23

标签: php wordpress sorting taxonomy

我的代码如下,但返回的列表不按字母顺序排序。

任何帮助?

<?php
    $termID = 4;
    $taxonomyName = "location";
    $termchildren = get_term_children( $termID, $taxonomyName );

    echo '<ul class="list">';
        foreach ($termchildren as $child) {
        $term = get_term_by( 'id', $child, $taxonomyName );
        echo '<li><span class="feature"><a href="' . get_term_link( $term->name, $taxonomyName ) . '">' .   $term->name . '</a></li>';
        }
    echo '</ul>';
?> 

1 个答案:

答案 0 :(得分:4)

使用此:

         $termID = 4;
        $taxonomyName = "location";
        $termchildren = get_term_children( $termID, $taxonomyName );

            foreach ($termchildren as $child) {
            $term = get_term_by( 'id', $child, $taxonomyName );

            $namearray[$term->name]= get_term_link( $term->name, $taxonomyName );

            }

        print_r($namearray);

        ksort($namearray);

         echo '<ul class="list">';
            foreach ($namearray as $key => $value) {
            echo '<li><span class="feature"><a href="'.$value.'">' .   $key . '</a></li>';
            }
        echo '</ul>';