Filter userlist by address attribute
PermalinkIs it possible to filter a userlist by the city filed of the address attribute?
I've tried
$ul->filterByAttribute('location', "London", "LIKE");
where 'location' is the handle of the address attribute
and
$ul->filterByAttribute('ak_city', "London", "LIKE");\
but neither work.
Many thanks
Thanks but this is what I was already doing.
When I use
$city='London'; $ul->filterByAttribute('ak_city',"%\n$city\n%",'like');
or
$ul->filterByAttribute('ak_city',"London",'like');
I get the error message
An unexpected error occurred. Call to a member function getController() on a non-object
You will need whatever handle you have given the overall address attribute, prefixed by ak_ .
The catch is that you could also get a positive result for things like "123 London Road, Brighton, ...", unless you are very careful about the match expression.
thanks for the reply I'm still getting an error
When I use
$ul->filterByAttribute('ak_location', "London", "LIKE");
where 'location' is the handle of the address attribute
I get the error
An unexpected error occurred. Call to a member function getController() on a non-object
Also check you have enabled searching for the attribute.
I looked in the table for the handle and it says it's ak_location_city
I have tried
$ul->filterByAttribute('ak_location_city', "London", "LIKE");
I'm still getting the same error as before
I also set the attribute in Members > Attributes > Location
Content included in user keyword search.
Field available in Dashboard User Search.
Is there any thing else I need to do?
Thanks
I am working off the top of my head, I don't have the code in front of me. Hence my posts are not 100% accurate.
What c5 core version are you using?
Have a look at the actual column data and build some simple tests based on that.
You can try leaving off the ak_ prefix. You can try leaving out 'Like' (I think it defaults to equals), and various combinations. Get it working for some obvious data in a simple case, then add the complexities back in.
I have some code that did something like this a while back. I will see if I can dig it out tomorrow.
filter('ak_shipping_address_city', '%London%','like');
Note its using filter, not filterByAttribute. I expect that is because its filtering on a search column that is part of an attribute, not on a complete attribute.
Thank you and your insomnia :-)
I tried it as you suggested without the 'ByAttribute' and it's working perfectly.
Thank you!
$ul->filter('ak_location_city', "London", "LIKE");
This it's an example i used to pass data from user to a page, you can see the address structure. Sorry but i haven't time today to think about this.
$Useradress=$ui->getAttribute('indirizo_struttura');
$newPage->setAttribute('street_address',array(
'address1'=>$Useradress->getAddress1(),
'address2'=>$Useradress->getAddress2(),
'city'=>$Useradress->getCity(),
'region'=>$Useradress->getStateProvince(),
'country'=>$Useradress->getCountry(),
'postal_code'=>$Useradress->getPostalCode(), ));
Maybe with some changes this works for you:
$city='London';
$ul->filterByAttribute('ak_city',"%\n$city\n%",'like');
Usually i use this but not in address attribute:
$ul->filterByAttribute('location',"%\n$city\n%",'like');