list of users/authors – how to order/sort by ‘first_name’?
-
Hi Guys,
quick question (i think)
I have a template page for listing the users/authors we have. Unfortunately i can’t work out how to order the page by the ‘first_name’ of each user.
It currently lists based on ‘nicename’ or ‘id’
Can anyone help me out?
Here is the template:
<?php /* Template Name: Member's Contact Template */ ?> <?php get_header(); ?> <?php if ( $user_ID ) : // Check if logged in ?> <table class="membercontacts"> <tr> <td><h2>name</h2></td> <td align="left"><h2>phone</h2></td> <td align="left"><h2>email</h2></td> </tr> <?php global $wpdb, $table_prefix; // set global WP vars needed for script $order = 'user_nicename'; // set order for users table query $user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users ORDER BY $order"); // query users foreach($user_ids as $user_id) : // start authors' profile "loop" $user = get_userdata($user_id); // retrieve author (i.e. user) details endforeach foreach($user_ids as $user_id) : // start authors' profile "loop" $user = get_userdata($user_id); // retrieve author (i.e. user) details $level = $table_prefix . 'user_level'; // set 'user_level' usermeta meta_key record $user->user_level = $user->$level; // assign 'user_level' property to $users $role = $table_prefix . 'capabilities'; // set 'role' usermeta table meta_key record $user->role = array_keys($user->$role); // assign 'role' property to $user $user->role = $user->role[0]; // make sure $user->role is not an array $phone = get_cimyFieldValue($user_id, 'PHONE'); $visible_member = get_cimyFieldValue($user_id, 'VISIBLE_MEMBER'); if ($visible_member == 'YES') : if( ('admin' != $user->user_login) && ($user->user_level >= 0) ) : ?> <tr align="left" valign="top"> <td> <?php echo $user->first_name; ?> <?php echo $user->last_name; ?> </td> <td> <?php if($phone) : ?> <?php echo $phone; ?> <?php endif; ?> </td> <td> <?php if($user->user_email) : ?> <a href="mailto:<?php echo antispambot($user->user_email, 1); ?>"><?php echo antispambot($user->user_email); ?></a> <?php endif; ?> </td> </tr> <?php else: endif; // end of admin and user_level test else: endif; // end loop check of CIMY viewable_members equals true endforeach; // end of authors' profile 'loop' ?> </table> <div class="divider"></div> </div> <?php get_footer(); ?> <?php include (TEMPLATEPATH . '/sidebar1.php'); ?> </body> <?php else : // User is not logged in ?> </div> <div class="content"> <?php get_footer(); ?> </body> </div> <?php endif; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘list of users/authors – how to order/sort by ‘first_name’?’ is closed to new replies.