如何按姓名的字母顺序对用户进行排序?在插件UPME中

时间:2016-04-29 作者:Diana

我有以下代码:

<?php
  class UPME_List_Cards {

  public $upme_options;


  public function __construct() {
    global $upme;
    add_shortcode(\'upme_latest_members_list\', array($this,\'latest_members_list\'));
}

public function latest_members_list($atts){
    global $upme_template_loader,$upme_list_card_params;
    extract( shortcode_atts( array(
        \'limit\'   => 10 ,
        \'user_role\' => \'\',
        \'template\' => \'members_icon_mini\',
      ), $atts ) );

    $admin_users = get_users(\'role=administrator&orderby=registered&order=DESC\');
    $admin_users_list = array();
    foreach ($admin_users as $admin_user) {
        array_push($admin_users_list,$admin_user->ID);
    }

    $display = \'\';

    $args = array(
                \'exclude\'=> $admin_users_list,
                \'number\' => $limit,
                \'orderby\' => \'registered\',
                \'order\'   => \'desc\',
                \'meta_query\' => array(
                    \'relation\' => \'AND\',
                    0 => array(
                        \'key\'     => \'upme_user_profile_status\',
                        \'value\'   => \'ACTIVE\',
                        \'compare\' => \'=\'
                        ),
                    1 => array(
                        \'key\'     => \'upme_approval_status\',
                        \'value\'   => \'ACTIVE\',
                        \'compare\' => \'=\'
                        ),
                    2 => array(
                        \'key\'     => \'upme_activation_status\',
                        \'value\'   => \'ACTIVE\',
                        \'compare\' => \'=\'
                        )
                )
            );

    if($user_role != \'\'){
        $args[\'role\'] = $user_role;
    }

    $users_query = new WP_User_Query( $args );
    $results = $users_query->get_results();
    $upme_list_card_params[\'results\'] = $results;

    ob_start();

    switch($template){
        case \'members_icon_mini\':                
            $upme_list_card_params[\'css_class\'] = \'upme-list-card-default-mini\';
            $upme_template_loader->get_template_part(\'members-icon-mini\');        
            break;

        case \'members_icon_mini_rounded\':                
            $upme_list_card_params[\'css_class\'] = \'upme-list-card-default-mini-rounded\';
            $upme_template_loader->get_template_part(\'members-icon-mini\');        
            break;
    }

    $display = ob_get_clean();

    return $display;       
}

}

$upme_list_cards = new UPME_List_Cards();
那个么,在UPME插件中,如何按名称的字母顺序排列用户?

1 个回复
SO网友:Usce

Diana您必须更改此数组中的代码行

 $args = array(
                \'exclude\'=> $admin_users_list,
                \'number\' => $limit,
                \'orderby\' => \'registered\',
                \'order\'   => \'desc\',
                \'meta_query\' => array(
                    \'relation\' => \'AND\',
                    0 => array(
                        \'key\'     => \'upme_user_profile_status\',
                        \'value\'   => \'ACTIVE\',
                        \'compare\' => \'=\'
                        ),
                    1 => array(
                        \'key\'     => \'upme_approval_status\',
                        \'value\'   => \'ACTIVE\',
                        \'compare\' => \'=\'
                        ),
                    2 => array(
                        \'key\'     => \'upme_activation_status\',
                        \'value\'   => \'ACTIVE\',
                        \'compare\' => \'=\'
                        )
                )
            );
此行\'orderby\' => \'registered\', 您将注册表更改为\'name\' 所以这条线看起来像这样\'orderby\' => \'name\', 并将此行从desc更改为asc\'order\' => \'desc\', 将其更改为\'order\' => \'asc\',.

相关推荐

显示作者姓名PHP(自制插件)

我有一个需要帮助的问题,因为我自己找不到解决办法。我接管了一个网站,之前有人在那里创建了一个自制插件。。使用默认插件“Contact Form 7”,用户可以在页面上创建帖子。()https://gyazo.com/c8b20adecacd90fb9bfe72ad2138a980 )关于自行创建的插件“Contact Form 7 extender”,帖子是通过PHP代码在后台生成的(https://gyazo.com/115a6c7c9afafd2970b66fd421ca76a3)其工作原理如下:如果