I want to return an array, based on the order in which category IDs are included.
Something like:
$categories = array();
$cat_ids = array(5,4,7,6);
foreach ( $cat_ids as $id ) {
$categories[] = get_category( $id );
}
But how to modify my code to work like this? 🙂
<?PHP
$args = [‘hide_empty’ => 0,];
$cats = get_categories($args);
foreach ($cats as $cat) {
$image = get_field(‘cat_image’, $cat);
echo ‘
<li>
<a href=”‘ . get_category_link($cat->term_id) . ‘”><img src=”‘.$image[‘url’].'” alt=”‘ . $cat->name . ‘” /></a>
<span class=”crp_title” style=”bottom:4px;”>’, (
strlen($title= the_title(”, ”, false)) > 48 ?
substr($title, 0, 48) :
$cat->name
), ‘</span>
</li>’;
}?>
Thank you in advance
[ad_2]