Support

Account

Home Forums General Issues Order Post Objects by menu_order Reply To: Order Post Objects by menu_order

  • Install the plugin Post Types Order

    Solution is use:

    
    function objectRSort(&$object, $key) 
        { 
            for ($i = count($object) - 1; $i >= 0; $i--) 
            { 
              	$swapped = false; 
              	for ($j = 0; $j < $i; $j++) 
              	{ 
    		  		if(is_numeric($object[$j]->$key))
    				{
                   		if ($object[$j]->$key > $object[$j + 1]->$key) 
                   		{ 
                        	$tmp = $object[$j]; 
                        	$object[$j] = $object[$j + 1];       
                        	$object[$j + 1] = $tmp; 
                        	$swapped = true; 
                   		} 
    			 	} 
    				else
    				{
    					if (strtolower($object[$j]->$key) > strtolower($object[$j + 1]->$key)) 
                   		{ 
                        	$tmp = $object[$j]; 
                        	$object[$j] = $object[$j + 1];       
                        	$object[$j + 1] = $tmp; 
                        	$swapped = true; 
                   		} 
    				}
    			} 
    			
              	if (!$swapped) return; 
            } 
        } 
    

    And just include this code:

    
    $child_pages = get_field('child_pages'); 
    objectRSort($child_pages, 'menu_order');