Filter and Hooks

Sort the categories in an alphabetical order in the presence of plugin

”Category Order and Taxonomy Terms Order’ plugin’,  order Categories and all custom taxonomies terms (hierarchically) using a Drag and Drop Sortable javascript capability.

When the condition arrives, where we want  to order particular  categories / taxonomies  in the  alphabetical order, then we can use the ksort. Check the example :

function sortCategories($items) {
    $placeHolder = [];
    
    foreach ($items as $item) {
        $placeHolder[$item->name]= $item;
    }
    
    ksort($placeHolder);
    
    return $placeHolder;
}
   $args = array(
		'orderby'  => 'name', 
   		'order'    => 'ASC',
	        'child_of' => 0,
	         'parent'  => 0,
	         'hide_empty'  => 0,
	         );
	                
$categoriesT = get_categories( $args );
$categories = sortCategories($categoriesT);

echo '<ul>'
 foreach($categories as $category) {
            echo '<li>' . $category->name.'</li>';
        }
echo '</ul>'

 

Views: 18

Standard