是的,这是因为你按名字和升序对它们进行排序。因为\'orderby\' => \'name\', \'order\' => \'ASC\'
是默认设置。
尝试:$term_names = wp_get_post_terms($post->ID, \'marcamodelo\', array(\'fields\' => \'names\', \'orderby\' => \'name\', \'order\' => \'DESC\', ));
这应该是另一种方式。
这里有orderby和order可以使用哪些参数的文档:https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
edit:可能您希望这样(不太确定详细的正确语法):
<div class="box2">
<div class="faixa">
<div class="marca">MARCA <div class="marca">
<?php
$parents = wp_get_post_terms($post->ID, \'marcamodelo\', array(\'parent\' => 0));
if ( ! empty( $parents ) ) {
// echo $parents[0];
var_dump($parents);
}
?>
</div></div>
<div class="modelo">MODELO <div class="marca">
<?php
$childs = wp_get_post_terms($post->ID, \'marcamodelo\', array(\'fields\' => \'names\', \'parent\' => $parents[0]->ID ));
if ( ! empty( $childs ) ) {
// echo $childs[0];
var_dump($childs);
}
?>
</div></div>
</div>