2014-01-30 24 views
0

我想通過user_meta'org'對此表進行排序,現在按用戶名排序。請幫忙。謝謝!我想通過user_meta org排序這個表,現在它按用戶名排序。

 <table width="100%" border="0" cellpadding="0"> 
     <tbody> 
     <?php 
     // Get all users order by amount of posts 
     $allUsers = get_users('order=ASC'); 

     $users = array(); 

     // Remove subscribers from the list as they won't write any articles 
     foreach($allUsers as $currentUser) 
     { 
     if(!in_array('administrator', $currentUser->roles)) 
     { 
     $users[] = $currentUser; 
     } 
     } 

     ?> 

     <?php get_header(); ?> 


     <?php 


     foreach($users as $user) 
     { 
     ?> 

     <tr> 
     <th><?php echo get_user_meta($user->ID, 'org', true); ?></th> 
     <td scope="row"><?php echo $user->first_name . " " . $user->last_name; ?></td> 
     <td><?php echo get_user_meta($user->ID, 'pnumber', true); ?></td> 
     <td><a href="<?php echo $user->user_url; ?>" target="_blank"><?php echo $user->user_url; ?></a></td> 
     </tr> 
     <tr> 

     <?php 
     } 
     ?> 
     </tbody> 

我想循環通過帳戶名稱和元信息,並把它們放在order_by user_meta組織。請幫忙。提前致謝!

回答

0

那麼,一開始可能是在get_users中使用queryby的orderby參數。但它只適用於以下字段:'ID','登錄','nicename','email','url','registered','display_name'或'post_count',例如:

$allUsers = get_users('order=ASC&orderby=ID'); // the default orderby is login 

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

但是,如果我理解正確的話,好像你真正需要做的是一樣的東西

$users[] = $currentUser; 
$user_org = get_user_meta($currentUser->ID, 'org'); // read user_meta org 
$user[count($user-1)]->org = $user_org; 

(見http://codex.wordpress.org/Function_Reference/get_user_meta

在你的控制結構的然後根據'組織'值對數組進行排序。怎麼樣? http://www.php.net/manual/en/array.sorting.php

+0

謝謝豪爾赫,我很難讓這個工作。 – Eric

+0

對不起,我沒有真正測試代碼只是一個想法。你管理了嗎? (如果是這樣,請將我的答案標記爲有用:D) –

+1

我閱讀了您所引用的文章,但並未完全按照我的意願進行,但我只將該組織與暱稱相匹配,並將顯示名稱更改爲暱稱,並更改了orderby = display_name感謝Jorge! – Eric