0

I am working on a wordpress site and i need to sort the array of some users by a custom column name 'IDlisting'

How can i sort this array by 'IDlisting'?

  Array 
    ( 
        [0] => stdClass Object 
            ( 
                [ID] => 6 
                [user_login] => adri 
                [user_url] =>  
                [user_status] => 0 
                [display_name] => adrian
                [IDlisting] => 6 
            ) 

        [1] => stdClass Object 
            ( 
                [ID] => 1 
                [user_login] => admin 
                [user_nicename] => admin 
                [user_activation_key] =>  
                [user_status] => 0 
                [display_name] => admin 
                [IDlisting] => 0 
            )
    )

i tried

$args  = array('orderby' => 'IDlisting',
                'order' => 'ASC'

      );
  $authors = get_users($args);

but it doesn't work

salathe
  • 51,324
  • 12
  • 104
  • 132
  • possible duplicate of [Sort php multidimensional array by sub-value](http://stackoverflow.com/questions/4508145/sort-php-multidimensional-array-by-sub-value) – Jon Apr 21 '12 at 12:29
  • @Jon, it is a question about WP API, not php sorting. – ozahorulia Apr 21 '12 at 12:31
  • $args looks correct. Are you sure it doesn't work? Try to sort it by different collumn, maybe problem is in IDlisting collumn's content? – ozahorulia Apr 21 '12 at 12:32
  • i don't think it's a duplicate because i have Array and then Object.. @Hast i tried with nicename,id and it works, but with IDlisting is not working, i don't know why – Placinta Salaru Alin Apr 21 '12 at 12:40
  • @PlacintaSalaruAlin areyou sure that fileds has different IDlisting? – ozahorulia Apr 21 '12 at 12:43
  • yes, all fields have different values – Placinta Salaru Alin Apr 21 '12 at 12:55
  • 1
    It seems like the value for orderby is limited. http://codex.wordpress.org/Function_Reference/get_users orderby - Sort by 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count'. – Selvaraj M A Apr 21 '12 at 13:58

2 Answers2

0

http://codex.wordpress.org/Function_Reference/get_users

orderby - Sort by 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count'.

Ordering by IDlisting is not natively supported

maiorano84
  • 11,574
  • 3
  • 35
  • 48
0

If you have the results in an array then you can just sort the array by hand.

<?php
header("Content-type: text/plain");

$data = array();
$data[] = array("id" => 6, "user_login" => "adri", "url" => "", "user_status" => 0, "display_name" => "adrian", "IDlisting" => 6);
$data[] = array("id" => 1, "user_login" => "admin", "url" => "", "user_status" => 0, "display_name" => "admin", "IDlisting" => 1);

var_dump($data);

echo "-----------------------------\n";

function cmp($a, $b)
{
    return $a["IDlisting"] - $b["IDlisting"];
}

uksort($data, "cmp");

var_dump($data);

?>
David Newcomb
  • 10,639
  • 3
  • 49
  • 62