Home Forums General Issues Sorting categories list by custom field


Sorting categories list by custom field

  • Couldn’t find a solution by searching the forms.

    I am trying to sort a categories list by my custom field, like so:


    It isn’t working though…Any ideas?

  • Hi @apinrise

    Unfortunately, taxonomies do not yet have a termdata table, and can’t be sorted / ordered.

    Please read the WP docs on the above function to learn what is and isn’t available.

    Perhaps you can look into a WP plugin that offers taxonomy ordering. I have used a few in the past with successful results.


  • Hi, perhaps this can help:
    you could get your categories into an array, then create another array where you use the custom fields as keys and the previous array items as values.
    then sort that second array and iterate it do display whatever you wanted to display.
    here’s a function that does that, customize the $args to meet your needs of course.

    function get_article_categories_by_disp_order(){
    $args = array(
    	'type'                     => 'post',
    	'child_of'                 => 2,
    	'parent'                   => '',
    	'orderby'                  => 'name',
    	'order'                    => 'ASC',
    	'hide_empty'               => 0,
    	'hierarchical'             => 1,
    	'exclude'                  => '',
    	'include'                  => '',
    	'number'                   => '',
    	'taxonomy'                 => 'category',
    	'pad_counts'               => false 
    	$categories = get_categories( $args );
    	$sorted_cats = array();
    	foreach($categories as $cat){
    		$ordr = get_field('display_order', 'category_'.$cat>term_id);
    		$sorted_cats[$ordr] = $cat;
    	return $sorted_cats;
Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Sorting categories list by custom field’ is closed to new replies.