users - get_users - Sort by a different meta_value than search criteria

I have this code and it works fine but it is not sorted.$args = array('meta_key' => 'pw_user_status�

I have this code and it works fine but it is not sorted.

    $args = array(
        'meta_key' => 'pw_user_status',
        'meta_value' => 'approved',
    );

    $users = get_users( $args );

I tried to sort the results using the below with no success...

$args = array(
        'meta_query' => array(
            array(
                'key' => 'pw_user_status',
                'value' => 'approved' ,
            ),
        ),
        'orderby' => 'meta_value',
        'meta_key' => 'user_lastname',
        'order' => 'ASC'
    );
$users = get_users( $args );

I have this code and it works fine but it is not sorted.

    $args = array(
        'meta_key' => 'pw_user_status',
        'meta_value' => 'approved',
    );

    $users = get_users( $args );

I tried to sort the results using the below with no success...

$args = array(
        'meta_query' => array(
            array(
                'key' => 'pw_user_status',
                'value' => 'approved' ,
            ),
        ),
        'orderby' => 'meta_value',
        'meta_key' => 'user_lastname',
        'order' => 'ASC'
    );
$users = get_users( $args );
Share Improve this question edited Apr 27, 2019 at 18:51 G-J asked Apr 27, 2019 at 18:42 G-JG-J 1014 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Should be 'meta_key' => 'last_name' instead of 'meta_key' => 'user_lastname'

$args = array(
    'meta_query' => array(
        array(
            'key' => 'pw_user_status',
            'value' => 'approved' ,
        ),
    ),
    'orderby' => 'meta_value',
    'meta_key' => 'last_name',
    'order' => 'ASC'
);
$users = get_users( $args );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745545531a4632320.html

相关推荐

  • users - get_users - Sort by a different meta_value than search criteria

    I have this code and it works fine but it is not sorted.$args = array('meta_key' => 'pw_user_status�

    3天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信