Posted by brightstorm on January 15, 2013 at 1:31pm
Hi
I'm working on a site in D7 for an estate agent which uses view with exposed filters to create a site wide search.
One of the fields in my search is for location, searching across the various town entered in each property.What I'm am trying to do is to automatically populate the location field in my search as a select list from the unique values entered in the property content type so that we only allow searching on locations that have properties within them.
Can anyone suggest an approach to achieve this? I've been looking at node entity and node entity reference field which havent harvested any results so far.
Thanks
Mike

Comments
Taxonomy?
Sounds like the location could do with being a taxonomy vocabulary?
With tagging turned on you could make this feature really simply.
hi t-lo thanks for the
hi t-lo
thanks for the reply.
i've been using the taxonomy vocab for other aspects of my properties content type but was hoping to dynamically make the search field from the towns field so that the location list wont have towns on it that dont have properties on the site. This is to try and reduce the chance of empty searches.
Am thinking it'll be part of the node reference family of plugins. Will continue sleuthing..
I'd still suggest using the
I'd still suggest using the taxonomy for ease of getting the full list up, then using hook_fom_alter to remove non referenced terms. (caching the result of this and rebuilding only after property node saves for a performance boost.)
so, to clarify, make the
so, to clarify, make the taxonomy list automatically from my location field and then remove items from it using hook form alter when we save subsequent properties?
Make the taxonomy list
Make the taxonomy list automatically from my location field (tagging enabled auto-complete taxonomy widget)
and then remove items from it using hook_form_alter which runs when the form is generated.
If that causes a performance drop, cache/variable_set the items that need removing with the hook_form_alter so you don't need to calculate them every time someone loads the page with the form on.
This store would need to be reset / recreated when you save properties.
You can probably do without the cache, at least until scaling up the amount of properties.
Taxonomy Orderable Tags
Thanks for the advice. i've added Taxonomy Orderable Tags and now got a taxonomy list that updates when i add a tag and i can reference this in my search field which is sweet.
Will need to look into getting hook_form_alter to remove taxonomy items from the list so we only get the live locations appearing. any pointers on how to do this (ive not used hook_form_alter before).
the client in only expecting to be listing <50 properties at a time so suspect caching wont be our primary concern.
Did you figure this out?
Did you figure this out? Sorry, I've been a bit behind this week..
hi T-lo, thanks for getting
hi T-lo,
thanks for getting back to me. I've managed to get locations into my taxonomy list but have yet to write the functionality in hook form alter to check the remove the taxonomy items if they dont exist in the in properties list.
in my hook_form_alter i've got access to the field
$form['field_address_town_tid']
which contains my list of locations from the taxonomy list. Could you explain how you'd manage removing the taxonomy items. would we do this at the stage when a property is saved?
ta
Two ways of getting the
Two ways of getting the taxonomy items you need to remove:
query in the hook_form_alter to find tid's that are linked too. something like unique in field table might be enough if the field is only used one the one content type.
If it's more complicated than that then maybe updating a serialized array of locations in use on property save (storing it with variable_set) might be the way forward.
Then its just a case of removing them from the #options array inside $form['field_address_town_tid']