Ordinare i termini della tassonomia in ordine alfabetico
Ho la seguente query:
<?php
$args = array(
'hide_empty' => false,
'orderby' => 'title',
'order' => 'DESC'
);
$terms = get_terms( 'projets-location', $args );
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
foreach ( $terms as $term ) { ?>
<h5 id="<?php echo $term->slug; ?>" class="filter-menu-item" data-filter=".<?php echo $term->slug; ?>">
<strong><?php echo $term->name; ?></strong>
</h5>
<?php }
} ?>
che mostra tutti i termini della tassonomia projets-location
, ho aggiunto gli attributi orderby
e order
sopra ma NON vengono ancora visualizzati in ordine alfabetico, sto facendo qualcosa di sbagliato o c'è qualche errore? Qualsiasi suggerimento sarebbe molto apprezzato!

Come indicato nel Codex di WordPress per get_terms
su questo link
https://developer.wordpress.org/reference/functions/get_terms/, i seguenti campi dei termini sono accettati nell'argomento order_by
: 'name', 'slug', 'term_group', 'term_id', 'id', 'description'
e stai utilizzando title
che non è tra i campi accettati, quindi questo potrebbe essere il problema.

Non sono riuscito a ordinare per nome utilizzando l'argomento orderby, quindi ho semplicemente usato una funzione di ordinamento ::
// ordina per nome ASC - cambia > con < per ordinare in DESC
function sortByName($a, $b) {
return $a->name > $b->name;
}
$terms = get_terms( 'projets-location', $args );
usort($subterms, 'sortByName');
foreach ( $terms as $term ) {
....

Prova con wpdb
<?php
global $wpdb;
$terms = $wpdb->get_results( "
SELECT
t.name,
t.slug
FROM
{$wpdb->prefix}term_taxonomy AS tt
INNER JOIN
{$wpdb->prefix}terms AS t
ON t.term_id = tt.term_id
WHERE
tt.taxonomy = 'projets-location'
ORDER BY
t.name DESC
" );
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
foreach ( $terms as $term ) { ?>
<h5 id="<?php echo $term->slug; ?>" class="filter-menu-item" data-filter=".<?php echo $term->slug; ?>">
<strong><?php echo $term->name; ?></strong>
</h5>
<?php }
} ?>
