0

I have the following code in my sidebar listing the terms or a custom taxonomy, these are names, first Name and last name. Is it possible to list them alphabetically by last name rather than the first name?

Thanks

<?php

$taxonomy = 'name';
$tax_terms = get_terms($taxonomy);
?>
<ul>
<?php
foreach ($tax_terms as $tax_term) {

echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '"title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' .    $tax_term->name.'</a></li>';
}
?>
</ul>
0

It is too specific of a condition for there to be a native way.

On other hand this is hardly complicated as simply sorting an array in PHP. You can use usort() with a small custom callback, containing your comparison logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.