Php 如何使用分类术语的ID';按特定顺序排列

Php 如何使用分类术语的ID';按特定顺序排列,php,wordpress,taxonomy,Php,Wordpress,Taxonomy,我试图通过使用分类术语的ID来获取分类术语,但我想按照特定的顺序对ID进行排序,而不仅仅是ASC $taxonomy = 'menu-food-categories'; $taxonomy_terms = get_terms( $taxonomy, 'orderby=ID&order=ASC&parent=0' ); 比如: $args_terms = array( 'post_in' => array(49,5,12,80)

我试图通过使用分类术语的ID来获取分类术语,但我想按照特定的顺序对ID进行排序,而不仅仅是ASC

$taxonomy = 'menu-food-categories';
$taxonomy_terms = get_terms( $taxonomy, 'orderby=ID&order=ASC&parent=0' );
比如:

$args_terms = array(
                       'post_in' => array(49,5,12,80),
                       'orderby' => post_in,
                       'parent' => '0'
                   );

          $taxonomy = 'menu-food-categories';
          $taxonomy_terms = get_terms($taxonomy, $args_terms);
你可以这样做

// Get term by id (''term_id'') in Categories taxonomy.
get_term_by('id', 12, 'category')

有关详细信息,请查看以下代码:

$taxonomy = 'menu-food-categories';
$args_terms_id_list = array(49,5,12,80);

foreach ($args_terms_id_list as $current_term_id){
    // Get term by id (''term_id'') in Categories taxonomy.
$taxonomy_terms = get_term_by('id', $current_term_id , $taxonomy)
// Do your code here
}

谢谢

自4.5.0以来,分类法应通过$args数组中的“taxonomy”参数传递:

可以使用的值

印刷品名称

foreach ($myterms as $key => $value) {
              echo $value->name;
}

名单有多长?难道你不能从数据库中取出数组,然后自己手动排序吗?列表只有6-7个ID,所以我完全可以这样做。我只是觉得有一种方法可以用wordpress的核心功能来实现。谢谢你的主意+1.
foreach ($myterms as $key => $value) {
              echo $value->name;
}