[wp-hackers] Querying users, orderby last name field?
Josh Pollock
jpollock412 at gmail.com
Sat Dec 21 01:21:30 UTC 2013
Otto-
Works like a charm. I ended up needing to add `'fields'=>'all_with_meta'`
to the array so I could use 'last_name' and 'first_name' in the return
array.
Looks like this:
$users = new WP_User_Query(array(
'meta_key'=>'last_name',
'orderby'=>'meta_value',
'fields'=>'all_with_meta'
));
Thanks,
Josh
On Fri, Dec 20, 2013 at 3:38 PM, Otto <otto at ottodestruct.com> wrote:
> On Fri, Dec 20, 2013 at 2:25 PM, Josh Pollock <jpollock412 at gmail.com>
> wrote:
>
> > There doesn't seem to be an orderby option in WP_User_Query to orderby
> last
> > name field. This leaves me wondering why not and what the most direct way
> > to do so would be.
> >
>
>
> Does this not work?
>
> new WP_User_Query(array(
> 'meta_key'=>'last_name',
> 'orderby'=>'meta_value',
> ));
>
> The last name is not a field that exists in the users table. It's a meta
> field. So you have to specify it and then order by the value of it.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list