include city and region for sorting/searh

This topic contains 14 replies, has 3 voices, and was last updated by  Stiofan O’Connor 7 years, 4 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #329671

    Ding Hua
    Expired Member
    Post count: 152

    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,
    YC

    #329862

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    I asked to Stiofan to have a look and possibly provide an example.

    Thanks

    #330048

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi 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

    #330111

    Ding Hua
    Expired Member
    Post count: 152

    Hi 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,
    YC

    #330117

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    You 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

    #330396

    Ding Hua
    Expired Member
    Post count: 152

    Hi 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,
    YC

    #330682

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    You 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

    #330698

    Ding Hua
    Expired Member
    Post count: 152

    Hi 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,
    YC

    #331048

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    I 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

    #331086

    Ding Hua
    Expired Member
    Post count: 152

    Hi Stiofan,

    Yes.Correct.
    Unless we read from database and filter based on the region for the select field in search.

    Rgds,
    YC

    #331093

    Ding Hua
    Expired Member
    Post count: 152

    Hi 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,
    YC

    #331109

    Ding Hua
    Expired Member
    Post count: 152

    And 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.

    #331123

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi 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

    #331343

    Ding Hua
    Expired Member
    Post count: 152

    Hi 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,
    YC

    #332088

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi 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

Viewing 15 posts - 1 through 15 (of 15 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket