문제

I am trying to get my taxonomy terms by using their ID's but I want to order my ID's in a specific order and not just ASC

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

Something like:

$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);
도움이 되었습니까?

해결책

you can do this by

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

as per this link

go through below code for more information ::

$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
}

Thank you

다른 팁

Since 4.5.0, taxonomies should be passed via the ‘taxonomy’ argument in the $args array: https://developer.wordpress.org/reference/classes/wp_term_query/__construct/

The values you can use https://developer.wordpress.org/reference/classes/wp_term_query/__construct/#source

$myterms = get_terms( array(
              'taxonomy' => 'menu-food-categories',
              'hide_empty' => false,
              'include' => array(49,5,12,80)
            ));

Print name

foreach ($myterms as $key => $value) {
              echo $value->name;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top