i have created this Php code to show a list by category.
Actually the list shows by alphabetical order.
I would like to show by create date.
<?php
$terms = get_terms( 'category' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
echo '<div class="product-category-list">';
$x = 1;
foreach ( $terms as $term ) {
echo "<div class='product-category-item bg-class-{$x}'>";
$icon = pods_field( 'category', $term->term_id, 'immagine_categoria', true );
$icon_url = $icon['guid'];
$icon_thumb = pods_image_url ( $icon_url, 'large', 0, false ) ;
$term_link = get_term_link($term);
echo '<div class="product-category-image">';
echo '<img src="'.$icon_thumb.'" alt="">';
echo '</div>';
echo '<div class="product-category-title">';
echo '<h3>'.$term->name.'</h3>';
echo '</div>';
echo '<div class="product-category-description">'.$term->description.'</div>';
echo '<div class="product-category-link">';
echo '<a class="product-category-button" href="'.$term_link.'">Visualizza Categoria</a>';
echo '</div>';
echo '</div>';
$x++;
if ($x > 3) {
$x = 1;
}
}
echo '</div>';
}
Thank you.
2
Answers
Lets try to sort the array first then display it. These are the some function that uses to sort the array.
Also check this article.
https://www.codegrepper.com/code-examples/php/php+array+sort+by+column
There is no
orderby
date
inget_terms()
. check below comments.So you can pass
'orderby => 'ID',
and'order' => 'DESC'
so this will give you category by created order. check below code.