[wp-hackers] WP Query - OrderBy Author

Jeremy Clarke jer at simianuprising.com
Mon May 14 15:24:00 UTC 2012

On Sun, May 13, 2012 at 3:01 PM, Robert Lusby <nanogwp at gmail.com> wrote:

> How would you order by Author Display Name, rather than ID, within
> WP_Query?
Display name is stored in the usermeta table and not in posts. I suspect
the simplest way would be to filter the query to:

   -  add the usermeta table to FROM
   - in WHERE add that posts.post_author = usermeta.user_id
   AND usermeta.meta_key = 'display_name'
   - ORDER BY usermeta.meta_value

Something along those lines anyway. Maybe someone has worked this out
already but I doubt it's in any of the core functions as it's pretty niche.
Seems hard to imagine why you'd really need these results anyway. Why not
get a list of users, then show one post for each of them? That seems like a
more logical way to go, as you'll have to write some weird code to add
headings with usernames to the results of the query you're looking for

Jeremy Clarke • jeremyclarke.org
Code and Design • globalvoicesonline.org

More information about the wp-hackers mailing list