Help with filterByAttribute()

Permalink
I want to be able get a list of users who have a specific value for an attribute I created.

I am trying to use the "filterByAttribute()" function found here:
http://www.concrete5.org/documentation/developers/permissions/user-...

As an example I have an attribute with a handle of "my_attribute_handle" and it currently has the value of "5".
Loader::model('user_list');
$ul = new UserList();
$ful = $ul->filterByAttribute('my_attribute_handle', '5', '=');
var_dump($ful);


however my $ful variable is NULL, even though I know there are several users with the attribute "my_attribute_handle" with the value of "5".

Thanks for any help.

 
12345j replied on at Permalink Reply
12345j
have you tried $ul->get()?
ssmereka replied on at Permalink Reply
Thank you, this was the missing link
cgrauer replied on at Permalink Reply
cgrauer
Try this:
Loader::model('user_list');
$ul = new UserList();
$ul->filterByAttribute('my_attribute_handle', '5', '=');
$ul->get();
var_dump($ul);
jero replied on at Permalink Reply
jero
It's not by any chance a <select> type attribute is it? I had endless fun with those. I found some documentation somewhere that said to do this:

$pl->filterByAttribute('color', "%\nGreen\n%', 'like');


which worked fine in my case.
mkly replied on at Permalink Best Answer Reply
mkly
The filters just build the query you still have to execute the query and get the results. This is so that you can add various sorts and filters before grabbing the list.
Loader::model('user_list');
$ul = new UserList();
$ul->filterByAttribute('my_attribute_handle', '5');
// This right here
$users = $ul->get();
// then do the whole
foreach($users as $user) {
  // do stuff
}


You can also use the more leet version of
Loader::model('user_list');
$ul = new UserList();
// magic
$ul->filterByUserMyAttributeHandle('5');
$users = $ul->get();
ssmereka replied on at Permalink Reply
Thank you, I read about these "Magic" functions, however was missing the $ul->get(), so that didn't work either. lol