Can I sort users by a custom attibute?
Permalink 4 users found helpful
Hello.
I'm setting up a page that displays all members of a particular user group. So far so good, but I can only seem to sort by the basic attributes and not custom ones. The UserList->sortBy() only seems to offer that. Instead, I want to sort by a custom user attribute, so that I can sort by the person's actual full name and not username.
Is this possible? Thanks.
I'm setting up a page that displays all members of a particular user group. So far so good, but I can only seem to sort by the basic attributes and not custom ones. The UserList->sortBy() only seems to offer that. Instead, I want to sort by a custom user attribute, so that I can sort by the person's actual full name and not username.
Is this possible? Thanks.
Did you find a solution to this? Anyone else have a solution? I have a single page with a UserList object and I need to sort the users by a particular attribute. Any thoughts?
Okay, so this is definitely possible, because you can do it on the backend on the users page. I'm going to dig into the code and will post what I find.
It was much easier than I expected...you just have to prefix your first "sortBy" parameter with "ak_" and then the attribute handle. Here's an example:
Pretty easy :)
$userList = new UserList(); $userList->sortBy('ak_last_name', 'asc');
Pretty easy :)
That's REALLY great !!!!
Hi
is this different in the newest version? I need to sort a few hundred users by lastname and my code does not seem to work.
This is on my members.php
Can you help me? Thanks :-)
is this different in the newest version? I need to sort a few hundred users by lastname and my code does not seem to work.
This is on my members.php
<?php $av = Loader::helper('concrete/avatar'); Loader::model('user_list'); $ul = new UserList(); $ul->filterByGroup('Society Members'); $ul->sortBy('ak_lastname', 'asc'); $ul->setItemsPerPage( 1000 ); foreach($users as $user) { $joindate = $user->getAttribute('joindate'); $lastname = $user->getAttribute('lastname'); $firstname = $user->getAttribute('firstname'); $middleinit = $user->getAttribute('middleinit'); $spouse = $user->getAttribute('spouse'); $title = $user->getAttribute('title'); $officer = $user->getAttribute('officer');
Viewing 15 lines of 22 lines. View entire code block.
Can you help me? Thanks :-)
Hey Shotrox -
Did you ever get this working?
Did you ever get this working?