$args for get_terms() to return ORDER BY FIELDS

I want to use get_terms() for a taxonomy in such as way as to emulate MySQL's ORDER BY FIELD e.g., ...FIELD ('aaa','ccc','bbb','eee','ddd')

A var_dump snippet currently looks like:

object(WP_Term)#1861 (10) { ...["slug"]= string(3) "eee" 
object(WP_Term)#1862 (10) { ...["slug"]= string(3) "bbb" 
object(WP_Term)#1863 (10) { ...["slug"]= string(3) "aaa" 
object(WP_Term)#1864 (10) { ...["slug"]= string(3) "ccc" 
object(WP_Term)#1865 (10) { ...["slug"]= string(3) "ddd" 

Have been reading the codex but I'm missing something. Here's what I have:

$args = array(
    'orderby'   = 'include', 
    'order'     = 'ASC',
    'include'   = array('aaa','ccc','bbb','eee','ddd'),
    'fields'    = 'all', 
);    

$roles = get_terms( 'role', $args );

As you can see above, the taxonomy in wp_mc_term_taxonomy is "role" and the slug's are 'aaa','ccc','bbb','eee','ddd' in wp_terms

What is the secret sauce? Thanks!

Topic wp-parse-args terms Wordpress

Category Web


From WP_Term construct docs:

'include' (array|string) Array or comma/space-separated string of term ids to include. Default empty array.

Looks like you may need to change your includes array to hold ID's instead of slugs.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.