Hello. I'm trying to do a search that returns the groups that have an specific word in their name.
For example, if i have this groups:
- Culture in France
- Culture in Spain
- Gastronomy in Spain
A search by "Spain" will return the second and third groups.
I'm trying this code:
$params = array(
'metadata_names' => 'universal_categories',
'types' => 'group',
'limit' => '10000',
'metadata_name_value_pairs' => array('name' => 'name', 'value' => '%'.$query.'%', 'operand' => 'LIKE')
);
$objects = elgg_get_entities_from_metadata($params);
But it doesn't work. How can I do this?
Regards.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Kevin Jardine@kevin
Kevin Jardine - 0 likes
- Kevin Jardine@kevin
Kevin Jardine - 0 likes
- Kevin Jardine@kevin
Kevin Jardine - 0 likes
- Angel Aparicio@angel_aparicio
Angel Aparicio - 0 likes
- ihayredinov@ihayredinov
ihayredinov - 0 likes
- Kevin Jardine@kevin
Kevin Jardine - 0 likes
- ihayredinov@ihayredinov
ihayredinov - 0 likes
- Angel Aparicio@angel_aparicio
Angel Aparicio - 0 likes
- Greg@gregbray
Greg - 0 likes
You must log in to post replies.I think you want:
$params = array(
'type' => 'group',
'limit' => 0,
'metadata_name_value_pairs' => array('name' => 'universal_categories', 'value' => '%'.$query.'%', 'operand' => 'LIKE')
);
(setting the limit to 0 means no limit).
Ah, sorry. I missed the point that this value is in the group name.
Group names are not metadata.
Instead I think that you could code this as:
$params = array(
'type => 'group',
'wheres' => array("e.name LIKE '%$query%'"),
'limit' => 0,
);
$objects = elgg_get_entities($params);
It doesn't work:
Unknown column 'e.name' in 'where clause'
The query:
SELECT DISTINCT e.* FROM elgg_entities e WHERE e.name LIKE '%espiritualidad%' AND ((e.type = 'group')) AND (e.site_guid IN (1)) AND ( (1 = 1) and e.enabled='yes') ORDER BY e.time_created desc
The table elgg_entities don't have the colum "name". :-/
You need to do a join on a groups table, and use g.name
Ismayil is right, that should have been:
$params = array(
'type => 'group',
'joins' = array("INNER JOIN groups g ON (g.guid = e.guid)"),
'wheres' => array("g.name LIKE '%$query%'"),
'limit' => 0,
);
$objects = elgg_get_entities($params);
Bit of a wart in the API that you need to do the little dance for certain values that aren't metadata.
I believe elgg_get_entities_from_attributes() is coming with 1.9, that will make life easier.
Thanks, it works perfectly!!
I somewhat new to Elgg, but I'm having the same issue. If you search on only part of a group name, we want all of the groups that match to be returned, but zero results are coming back. I generally understand what the code above is doing, but I'm not clear about where it needs to go. Any pointers would be appreciated greatly. Thanks.