我正在尝试通过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 :(得分:0)
好吧,一个开始可能是在get_users中使用查询的orderby参数。但它仅适用于以下字段:'ID','login','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)
在您的控制结构中,然后根据'org'值对数组进行排序。怎么样? http://www.php.net/manual/en/array.sorting.php