Ottenere i Termini per ID con ordine degli ID
Voglio ottenere i Termini per ID mantenendo l'ordine degli ID. Ma non funziona, WordPress cambia automaticamente l'ordine.
Il mio codice-
$catsArray = array(159, 155, 143, 153, ......);
$series = get_terms( array(
'taxonomy' => 'ctc_sermon_series',
'number' => 9,
'offset' => $offset,
'include' => $catsArray,
'hide_empty' => false,
) );
E il risultato-
(
[0] => WP_Term Object
(
[term_id] => 155
[name] => 10
[slug] => 10
[term_group] => 0
[term_taxonomy_id] => 155
[taxonomy] => ctc_sermon_series
[description] =>
[parent] => 0
[count] => 1
[filter] => raw
)
[1] => WP_Term Object
(
[term_id] => 159
[name] => 14
[slug] => 14
[term_group] => 0
[term_taxonomy_id] => 159
[taxonomy] => ctc_sermon_series
[description] =>
[parent] => 0
[count] => 1
[filter] => raw
)
[2] => WP_Term Object
(
[term_id] => 153
[name] => Nome 8
[slug] => name-8
[term_group] => 0
[term_taxonomy_id] => 153
[taxonomy] => ctc_sermon_series
[description] => Nome 8 Des
[parent] => 0
[count] => 1
[filter] => raw
)
[3] => WP_Term Object
(
[term_id] => 143
[name] => Serie 1
[slug] => series-1
[term_group] => 0
[term_taxonomy_id] => 143
[taxonomy] => ctc_sermon_series
[description] => Descrizione Serie 1
[parent] => 0
[count] => 3
[filter] => raw
)
)
Mi aspetto di ottenere prima il termine con ID-159, ma ogni volta ottengo prima il risultato dell'ID-155. Ho bisogno di ottenere il risultato secondo la sequenza dell'array degli ID.
Grazie in anticipo :)
Quindi credo che la domanda sia come ottenere i termini nell'ordine degli ID forniti - che potrebbero non essere ordinati in modo crescente o decrescente, ma in un ordine casuale.
Sorprendentemente, penso che ci sia una scorciatoia per questo in WP - chi lo avrebbe mai detto? Questo, credo, è ciò che vuoi usare:
$catsArray = array(159, 155, 143, 153, ......);
$series = get_terms( array(
'taxonomy' => 'ctc_sermon_series',
'number' => 9,
'offset' => $offset,
'include' => $catsArray,
'hide_empty' => false,
'orderby' => 'include', // <---
) );
Spero che questo sia d'aiuto!

Questo potrebbe funzionare per te, anche se non l'ho testato.
$catsArray = array(159, 155, 143, 153, ......);
$series = get_terms( array(
'taxonomy' => 'ctc_sermon_series',
'number' => 9,
'offset' => $offset,
'include' => $catsArray,
'hide_empty' => false,
'orderby' => 'term_id',
'order' => 'DESC', // oppure ASC
) );

Basta utilizzare il parametro 'fields'.
wp_get_post_terms($post_id, 'some_taxonomy', array('fields' => 'ids'))
Leggi questo https://wp-kama.com/function/wp_get_post_terms
