根据您的评论(并希望对问题进行编辑):
我是这样做的:foreach ( $termchildren as $child ) { $term =
get_term_by( \'id\', $child, $taxonomy_name, array( \'orderby\' => \'name\',
\'hide_empty\' => 0) );
已格式化:
foreach ( $termchildren as $child ) {
$term = get_term_by(
\'id\',
$child,
$taxonomy_name,
array(
\'orderby\' => \'name\',
\'hide_empty\' => 0
)
);
get_term_by
不接受数组作为第四个参数,或者实际上不接受任何参数。您不能只是构建参数并期望它们工作。你需要看看
Codex 和
the source.
此外get_term_by
而不是在这里进行排序。运行时会进行排序get_term_children
, 尽管如此does not take a parameter that will order the results.
您可以对结果集进行排序:
$term_id = 61;
$taxonomy_name = \'tribe_events_cat\';
$termchildren = get_term_children( $term_id, $taxonomy_name );
$children = array();
foreach ($termchildren as $child) {
$term = get_term_by( \'id\', $child, $taxonomy_name );
$children[$term->name] = $term;
}
ksort($children);
// now $children is alphabetized
echo "<script type=\'text/javascript\'>function taclinkch(x){var y=document.getElementById(x).value;document.location.href=y}</script>";
echo "<form action=\'\'> <select name=\'eventcats\' id=\'eventcats\' onchange=\'taclinkch(this.id)\'>";
echo "<option value=\'\'>Select a Topic</option>";
foreach ( $children as $child ) {
$term = get_term_by( \'id\', $child->term_id, $taxonomy_name );
echo "<option value=\'" . get_site_url() . "/events/category/". $term->slug." \'>" . $term->name . "</option>";
}
echo "</select></form>";