I get an Array from wordpress get_categories and i need to sort it with a value that is inside an ACF field. This value is composed like this : number | year , for example 2 | 2017

I need to sort with number (that can be 1, 2, 3...), this will determine my order rank.

To get my categories array i do :

  $args = array(
    'taxonomy' => 'category',
    'hide_empty' => 0
  $c = get_categories($args);

And i think i must add a for each after that with a usort but i don't know how to do. To get my ACF field i could do this:

 get_field('millesime', 'category_'.$cat->term_id);

And this to extract the number:

 substr ( get_field('millesime', 'category_'.$cat->term_id),0,1)

But my problem is that i don't know how to make it work with USORT.

Thanks for help.


In you $args you need to make sure to order your categories like so:

 $args = array(
'taxonomy' => 'category',
'orderby' => 'date',
'order'   => 'DESC',
'hide_empty' => 0
  ); $c = get_categories($args);

Did you make a custom taxonomy and use that within ACF?

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.