Skip Navigation

[Resolved] How best to integrate City values with country relationship?

This support ticket is created 5 years, 5 months 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: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by DieterR7285 5 years, 5 months ago.

Assisted by: Waqar.

Author
Posts
#1292199

Tell us what you are trying to do?
I am trying to dynamically import city names related to countries coming from a php file in XML format and make these available via a select able form field.
But since I did not find any documentation on a possible way I believe I have to create a table or custom post type structure and import those values via WP All Import. I need the Cities to be in a relationship with the countries. So what would be the best way!?

Is there any documentation that you are following?
I have looked into the following documentation:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/ and following
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/displaying-fields-of-grandparents/
https://toolset.com/documentation/user-guides/how-to-import-content-into-wordpress-using-csv/how-to-import-data-from-a-csv-file-using-the-wp-all-import-toolset-types-add-on-plugin/

As this is a form functionality to allow selection of fairly static content I am wondering if there is a plugin/database ready to use which provides the City - Country relationship. So could I use Toolset tap into the i.e. WooCommerce city - country list and make that available for other forms?

#1292349

Hi Dieter,

Thank you for contacting us and I'd be happy to assist.

Your questions can be divided into two main parts:

1. Structure:

The best way to store the data of Country and the related Cities would be to use two separate custom post types for each. This means that Country names will be stored in a custom post type "Countries" and City names will be stored in a custom post type "Cities".

To make a connection between these countries and cities, you can add a new one-to-many post-relationship, which means that each country can have multiple cities.
( ref: https://toolset.com/documentation/post-relationships/ )

2. Import:

As you noted, the "WP All Import" plugin can be used to import the posts in these new custom post types (i.e. Countries & Cities), and you can also add a column in the import file, to establish the relationship, during the import process.

Detailed instructions on the topic are available in the following guide:
https://toolset.com/documentation/user-guides/how-to-import-content-into-wordpress-using-csv/how-to-import-data-from-a-csv-file-using-the-wp-all-import-toolset-types-add-on-plugin/post-relationships/#example-2-one-to-many-relationships

I'm afraid, we don't have a pre-built module for the Country-City list, but you're welcome to submit a feature request for this at:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

It may also be possible to programmatically, extract the country-city list from the WooCommerce plugin and then generate the import file in the required format, but this will require a fair deal of custom code, which would be beyond the scope of the support that we provide.

For personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1295351

Hello Waqar,

Thanks for clarifying that you simply add custom post types for each "table" and connect them via the post relationships.

If I want that City - Country relationship to be presented as a select-able choice in a from. What exactly do I need to-do?

Kind regards

Dieter

#1295537

Hi Dieter,

Thanks for writing back and glad that my message helped.

> If I want that City - Country relationship to be presented as a select-able
> choice in a from. What exactly do I need to-do?

- There are two ways in which you can use Toolset Forms, to connect two posts from the front-end:
( after creating a relationship between Country and City post types )

1. If you'd like to connect one Country post to one City post, you can use a relationship form:
https://toolset.com/documentation/post-relationships/how-to-build-front-end-forms-for-connecting-posts/

2. When you'll create a post form to add or edit a City post, you'll also have the option to add the "Country" selection field. This field will allow you to join the current City post, with the selected Country post.
https://toolset.com/documentation/getting-started-with-toolset/publish-content-from-the-front-end/forms-for-creating-content/

regards,
Waqar

#1296927

My issue is resolved now. Thank you!