How can I show a list of Users with alphabetical headings? For example:
A
Adam
Alan
B
Bill
Bob
I've found examples that do it with Posts, but I can't figure out how to make it work with WP_User_query() :(
|
How can I show a list of Users with alphabetical headings? For example: A B I've found examples that do it with Posts, but I can't figure out how to make it work with |
|||||
|
|
After a good bit of tinkering I've come up with something. It's certainly not the BEST method, but since there's not a good way to do it through the core directly without having to do a bunch of array-reordering, I think SQL is a better solution here. Anyways, the SQL is as follows:
Nothing special going on there, it just gets all the values from the users table where there's a first name set. For the list you can just iterate through those results, it's pretty simple to do that. The only thing that you will need to do is get the headings to work right. If you store the heading, then do a case-insensitive compare, this should be pretty easy. For example (pseudocode):
Note: The SQL is tested, the PHP is not (obviously, since it's pseudocode). |
|||||||
|
|
@m0r7if3r provided the correct answer. For the sake of providing a directly usable snippet to anyone else looking at this issue, here's what I ended up using.
|
|||
|
|