timple-c
11/29/2017 - 8:11 PM

Ordena Categorias

Ordena Categorias

<?php  $categories = get_categories( array('parent' => 0, 'hide_empty' => 0, 'number' => 3)); ?>
				
				<?php // Ordena previamente con un ACF llamado "ORDEN" asignado a la categoria
				
					foreach($categories as $categoryKey => $category){
				
						$categoryToArray = (array)$categories[$categoryKey];
						$categoryToArray['order'] = (get_field("orden", "category_".$category->term_id))? get_field("orden", "category_".$category->term_id) : 0;
						$categories[$categoryKey] = (object)$categoryToArray;
					}
					
					function cmp($a, $b)
					{
						return strcmp($a->order,$b->order);
					}
					
					usort($categories, "cmp");
				
				?>