Skip Navigation

[Resolved] Show City (From a Complete Address) in Search

This support ticket is created 3 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+00:00)

This topic contains 18 replies, has 3 voices.

Last updated by wilsonC-2 3 years ago.

Assisted by: Jamal.

Author
Posts
#1998545

Tell us what you are trying to do?
I'm trying to extract the city from a complete address that is already plotted in Google Maps.

Is there any documentation that you are following?
I saw many solutions, but all of them are requesting to create a relationship between citi-state-country, using different custom fields. I used the address directly and it brought me the location in the map. So I was wondering if there is a way I exrtact the city automatically, without having to create a unique filter for the city.

Is there a similar example that we can see?

What is the link to your site?
The website is posted but still working with drafts for Toolset.

#1999085

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I would like to know - do you only want to display City as text on your page or you want to use the city to display on map?

#2000125

Hello,

I'm already using the full address to display Google Maps on the detailed page. Now I want to create the homepage with a search by city. I want to type the city on the search field, to bring results in this city. Since I don't have the city in a text field, I want o know if it's possible.

So, I have the full address that pulls the map markers, but I don't separate the city from the full address. On the homepage, I want to search by city name on the search field.

#2000199

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Toolset offers integration with Relevanssi plugin using which you can search within the custom fields.
=> https://toolset.com/course-lesson/searching-texts-in-custom-fields-with-toolset-and-relevanssi/

Can you please try that and see if that helps you to search city within your map address field.

#2001435
Address.JPG

So, Relevanssi does not work with the type of field Address. See the quote from the article that you sent me:

" You can add the following kinds of fields to Relevanssi’s index:
Single line
Multiple lines
WYSIWYG "

I have tried even so, and it won't show me this check box highlighted in yellow (image attached).

#2001463

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL and let me see if I can find any workaround for it.

Please share where exactly on what page you want to add your view as well as what view you created.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#2001559

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It looks like you are still editing your page. Can you please stop or share me a clone of your page as a test page where I should run the test.

#2001571

you can edit now. I closed all windows.

#2001819

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Do you mean that you want to search within the Address field "Marketing Agency Address" that is added to repeating field group "Exact Locations"? If not, Can you please tell me with what address field you want to search within.

Also, if you want to search within the field that is added to the Repeating Field Group, its not possible, as you can add or configure search fields that is directly belongs to the post that you set your view to query.

Having said that, if you want to search within the Repeating field group, you need to set your view to query Repeating Field Group and that it does not seems possible with View Block but if we use classic view, there is a option to set view to query Repeating field group.

But, first of all, I would like to confirm within what custom field you want to search ?
- Then I'll investigate if there is option to share any workaround with you or not.

#2001943

Yes, I want to search within "Marketing Agency Address" .

#2004393

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Minesh is on vacation, if you don't mind, I'll continue with you on this ticket.

To be able to have a dropdown filter for the city, the city needs to be saved on its own field. Toolset Maps only uses the full address as a string, the longitude and latitude as a cached value, to be used in maps, and distance search without querying the Google/Azure Maps APIs.

That will need some custom code, depending on the current state of your website. Either using PHP code or using Javascript. For example, if you are allowing users to enter their addresses in a Toolset form, you can implement a Javascript solution that will save the city in a custom field, as soon as Toolset gets a response from Google/Azure API. Check an example here for inspiration https://toolset.com/forums/topic/separating-content-from-the-address-field/#post-522506

If you are adding the addresses from the backend, or if you have existing data, you will need to use PHP code that will query Google/Azure Maps APIs, the same way Bigul did with his shortcode on the following reply, and save the city in a custom field.
https://toolset.com/forums/topic/google-maps-with-zipcode-cityname/#post-183853
Check the Google Maps API here hidden link
Note that not all the responses from Google Maps may return a city entry. In fact the first example in that article for address "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA" does not specify clearly what is the city of that address.

I hope this helps. Let me know if you have any questions.

#2004395

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

It is also worth to mention, that you can also use PHP code when offering the users to add the addresses through a Toolset form. Your PHP code should hook to the cred_save_data action:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#2007983

Ok, thank you for all the support. I created a single field for the city and added a search field with a filter comparison value as a string and an option to compare as "like". Even putting the same name of the city doesn't bring me any result. This also happens with the search by name. Can you please check what could be going wrong there?

#2008299

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

I can see the issue with the search per name, I tried to reconfigure the view and test if it will work when searching only the title and content, but I am unable to save the view, and the website becomes unresponsive. Check this screenshot hidden link

I would like to take a copy of your website and debug this locally. Would you allow me to take the copy?

Regarding the search with the city, I believe you are talking about this field, right? hidden link
If that's the case, I am afraid, it won't work. Because this field is a custom field inside the Repeatable Field Group, which is, under the hood a separate custom post type. An RFG is a hidden custom post type, linked to its parent custom post type using a hidden one-to-many relationship. Currently, Toolset does not allow filtering a custom post type(Marekting Agency) using custom fields(city) in a related custom post type(RFG: Locations). Does it make sense?
I would suggest that you implement the city, and the address field in the parent Custom Post Type(Marketing Agency), you can configure it to hold several values(Allow multiple instances of this field). In that case, you can use it to filter the Marketing Agency post type.

However, I believe a custom code solution may be implemented. The custom solution, will search for the RFG items that matches the search, use the toolset relationship API to get the parent posts, and then alter the view's query arguments to search only within these parent posts(post__in argument):
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
- https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters

#2008733

Hey Kamal, thank you for your constructive answer.

Regarding the first comment about not being able to save the website view, can you please send me your IP in a private message to whitelist it? This may be the problem. Also, I have problems when using a VPN too. If it doesn't work, I can let you make a copy locally.

Regarding the City field in the parent Custom Post Type(Marketing Agency) to hold several values, isn't it also a good solution to make it as a taxonomy? Would it have the same behavior? If not, please let me know why the custom field would be a better option.

Thank you.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.