Adding post types like cities and zipcodes to admin panel

I want to add a simple list of cities and zipcodes that will be used for selection in the admin back end. I know I can create a custom post type - but that seems like overkill. Does wordpress support simple lists in another way?

All I really need is a textarea with a list of cities or zipcodes (one per line) and then save them somewhere.

The idea behind this is that we have a site that provides event listings. These events take place in certain cities and or zipcodes. We allow people to choose which CITY OR ZIPCODE (but not both) to select events from. So the city might be a dropdown in a search box and all we need is a list of cities to choose from. The same for zipcodes. This would not be the only use for cities and zipcodes - we could also use then as selection parameters for xml feeds etc.

Hope that makes things a little clearer.

Topic lists Wordpress

Category Web


I know I can create a custom post type - but that seems like overkill.

Why are you thinking like that I don't know. A custom post type is a simpler and easier way to sort out data of a specific type.

You can also go for the default post types: post or page with Custom Meta Fields for saving specific information like cities and zip code.

I don't know what your site's purpose is, how you are using the default post types etc.

I can suggest an easier way:

  • Use the default post type: post
  • Make a new category like: Address
  • Install Advanced Custom Fields plugin
  • Create new custom field-set with 2 fields: (1) Cities - textarea, (2) Zipcode - text
  • Now use the following location-combination:
    Advanced Custom Fields combination
  • Take the post title as a notation of the place

Using it is soooo easy that, it will show your custom fields only when the specific category (i.e. Address) is selected. And you can hide unnecessary fields when the "Address" category is selected.

After doing all of 'em, to show the data you just put using these fields, use a query on the front end using get_post_meta( $post->ID, 'your_key', true );, and show the data accordingly.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.