Display users in order by an “order” custom meta field

Alright, so here’s my current code (which works, displaying the users in order by ID and excluding the admin user):

$site_admin = "1";
$order = 'ID';
$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->usermeta WHERE ID != '$site_admin' ORDER BY $order"); // query users
foreach($user_ids as $user_id) : // start authors' profile "loop"
    $user = get_userdata($user_id);

    $level = $user->user_level;
    if ($level > 0) 
    { ?>

    ((information to display goes here))

   <?php  } ?>

What I’d like to do is add a meta field (I believe that’s the right terminology, but please correct if wrong), and I have already added that, then type in a number for each author.

Read More

Here’s how that was added (in functions.php):

<?php function my_new_contactmethods( $contactmethods ) {
$contactmethods['order'] = 'Order on the About Page'; 
return $contactmethods;
}
add_filter('user_contactmethods','my_new_contactmethods',10,1);?>

Last, I’d like to display the users in that order.

There are a number of related questions, but none that I could find that order the users by fields which are added in addition to the typical WordPress user information (e.g. ID, user_nicename, etc.) I can simply replace “ID” in the code above with “user_nicename” and that works fine, but I need to be able to manually set the order of each of the users, so none of the built-in fields will work for that purpose.

Related posts

Leave a Reply

1 comment