I am trying to display a list of the terms and descriptions from a custom taxonomy.
I have the following code which returns all terms with descriptions of a specified custom taxonomy in alphabetical order. However, I only want to show the five most recent terms, starting with the newest one.
<?php
$terms = get_terms('mytaxonomy');
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
echo '<ul>';
foreach ( $terms as $term ) {
$term = sanitize_term( $term, 'mytaxonomy' );
$term_link = get_term_link( $term, 'mytaxonomy' );
echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a><p>' . $term->description . '</p></li>';
}
echo '</ul>';
}
?>