include city and region for sorting/searh
This topic contains 14 replies, has 3 voices, and was last updated by Stiofan O’Connor 8 years, 2 months ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
December 23, 2016 at 11:56 am #329671
Hi ,
My client wish to include city and region in sorting and searching.
I try to put extra custom field for city and region so that I can configure to sort/search.I found this thread
https://wpgeodirectory.com/support/topic/autofill-category/and it is similar to my requirement.
Refer to attached file autofill.png , I wish to auto fill when user select region ( here mrt line ) to html variable mrt_line_ss ( i will later hide this field for front end users).
But not sure about variable for region and city.
Appreciate if you could give me sample code to make this work , like the above thread you explained. Thanks.
Rgds,
YCDecember 23, 2016 at 7:49 pm #329862Hi,
I asked to Stiofan to have a look and possibly provide an example.
Thanks
December 24, 2016 at 12:29 pm #330048Hi YC,
Do you want a dropdown in the main search form? If so you would have to add a select input and input all the city/region names exactly and a user could then select from the dropdown, and in the add listing we could hide the input and just add a snipped of php to save the region or city value on save.
If however you just want a autocompleate then the Near autocompleate in advanced search would do what you are after.Please explain more your needs.
Thanks,
Stiofan
December 24, 2016 at 2:15 pm #330111Hi Stiofan,
Yes , the one you mentioned.
Do you want a dropdown in the main search form? If so you would have to add a select input and input all the city/region names exactly and a user could then select from the dropdown, and in the add listing we could hide the input and just add a snipped of php to save the region or city value on save.Thanks.
Rgs,
YCDecember 24, 2016 at 2:58 pm #330117You want to mix the regions and cities together in one dropdown?
If you create the dropedown/s then i will give you the code to update the value on the fly when the post is saved.The adding to the search form is done via drag/drop.
Thanks,
Stiofan
December 25, 2016 at 2:40 pm #330396Hi Stiofan,
I want to use it for sorting and searching.
And Region and City are separate and not together.Region ( MRT LINE)
City (MRT station)Refer sorting.png for sorting ( i manually key in and test – to autofill hidden city and region fields later )
Refer search.png for searching ( i manually key in and test – to autofill hidden city and region fields later)For searching , how to make it selection dropdown list using existing custom location value ?
Rgds,
YCDecember 26, 2016 at 12:47 pm #330682You would need to make the actual custom fields selects not texts and fill in all the possible options, then the advanced search should work like how you want and then i can add the code to update that value on save.
Stiofan
December 26, 2016 at 2:15 pm #330698Hi Stiofan,
Yes.
I have created two custom fields select with option value.html variable are
mrt_line_ss ( for region)
mrt_station_ss (for city)
Rgds,
YCDecember 27, 2016 at 12:27 pm #331048I am still not sure that is the best way to do things as a user could select a region and then a non related city… but here is the code to update the values on post save
add_action('geodir_after_save_listing','_my_custom_fields_update_on_save',10,2); function _my_custom_fields_update_on_save($post_id,$postinfo_array){ geodir_save_post_meta($post_id, 'geodir_mrt_station_ss', $postinfo_array['post_city']); geodir_save_post_meta($post_id, 'geodir_mrt_line_ss', $postinfo_array['post_region']); }
Thanks,
Stiofan
December 27, 2016 at 1:01 pm #331086Hi Stiofan,
Yes.Correct.
Unless we read from database and filter based on the region for the select field in search.Rgds,
YCDecember 27, 2016 at 1:51 pm #331093Hi Stiofan,
It looks like the code not update the values on post save
Below is the post I tested with fronend.You can check with back end and the value are not saved.
http://35.161.183.78/wp-admin/post.php?post=221&action=edit
Rgds,
YCDecember 27, 2016 at 1:54 pm #331109And for the search , appreciate if there is a way that can help user select a region and then allow them to select related city. Thanks.
December 27, 2016 at 4:34 pm #331123Hi YC,
I am helping you with code example on how to use our hooks/filters but we don’t do custom work and we can’t build your custom search form for you, if you don’t have the skills to do this then you will need to hire a developer to do this for you.
Stiofan
December 28, 2016 at 2:28 am #331343Hi Stiofan,
Ok for the search.
But the code example is not updating the value.
Any variable there do I need to change to make it work as I do not know geo_directory variable name?Rgds,
YCDecember 28, 2016 at 4:54 pm #332088Hi YC,
I used the wrong hook, i have updated the code now, i have tested it on my site and it now works.
Thanks,
Stiofan
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket