Ordering get_categories() result by predetermined order

[ad_1]

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]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer