Skip Navigation

[Resolved] Is there a DB/CSV already created for US State/Cities, what's the best practice.

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 8 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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

Supporter timezone: Europe/Prague (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by Jan 8 years, 2 months ago.

Assisted by: Jan.

Author
Posts
#437226

I am trying to:
Create a rental site. Need to have US State and Cites. Is there a database that is already created (or CSV file) that can be easily imported? What is the best practice? Should they be taxonomies or Post Fields. Please advise.

Thank you ahead of time.

#438354

Jan
Supporter

Languages: English (English )

Timezone: Europe/Prague (GMT+01:00)

Hi Mark,
I believe you should set up the States, the Cities and the products for rent as custom post types and set up a post relationship between them. Then you can define custom fields for these post types as you see fit.

We don't have a CSV file for you to import directly, but there are several other options. First, you can read this document about post relationships: https://toolset.com/documentation/user-guides/creating-post-type-relationships/ - there is actually an example with a car rental site, which you might find useful.

For a practical example, you can explore a set of reference sites at http://discover-wp.com/. I think the Classifieds one might be closest to your goals.

Please let me know if this helped or if you have further questions.

#438670

It seems like that would be a common task for anyone creating sites which needs state/city fields.

I would like to have a pre-populated fields for State/City, so when a user creates a record, the State/City is there.

Any tips on importing States and Cities? States would be easy, but how does the import of cities and link (or establish a relationship) back to state?

Is there anyone in the community which can export State/City types?

I created a test site with the real estate theme, but it only had a few cities for one state. Is there a script that can be created to have State/City types populated.

Thank You.

#438837

Jan
Supporter

Languages: English (English )

Timezone: Europe/Prague (GMT+01:00)

Hi Mark, that depends - the set of data would be very different depending on the country or countries where the business is active. As conclusion, we don't believe that delivering other data than samples for demonstrating the features of Types and other Toolset plugins would be an effective use of our resources.

I'm sorry that I can't be of more help. But I will try to point you in the right direction: There are open data with US states and cities available online, for example here: hidden link

The CSV file can be read programatically in most scripting language. I suggest performing these steps in a script, once you have your post types for states and cities set up, and once you have created the post relationship between them:

1. For each state, create a post with a wp-cli command

wp post create

(details here: hidden link). You need to set the correct post type for state so that it matches your setup in Types.

2. For each city (in all states), also create a post with wp-cli (again, mind the post type).

3. Now, while processing a city, it is a good time to create an association between it and the state where it belongs. That is done by adding a postmeta

_wpcf_belongs_{$state_post_type_slug}_id

with the ID of the State post. Again, if you do this in a script, you can use a wp-cli command

wp post meta set

(details: hidden link).

After that, you should have a complete database of US States and Cities with working post relationships.

The forum ‘Types Community Support’ is closed to new topics and replies.