I am creating my first wordpress plugin. In it, the user will have the option to add new cities and view events on those cities.
My client requirement is that the URL must be like this
SITE_NAME/cities/NY
or
SITE_NAME/cities/Califonia
What is decided is that i will create a folder cities and If user tries to create a new city i will create a file in that folder with that city, Further more I will add the entry into the database as well.I will insert PHP code into the file as well.
Being new to WP plugins. Is my approach right (for creating files)? Is there any other way?
maiorano84 wrote a fairly comprehensive guide to setting up the stuff you need, Rather than relying on plugins though, I prefer to show you how to write a plugin to register the custom post type and taxonomy. To that effect, I wrote a little plugin that should do everything you need and it has plenty of comments and links to the docs so that you can understand the Why of things.
This plugin does several things
This plugin does not require any additional plugins to be installed, it is dependency free and only uses WP core.
As far as getting the correct URL Structure, I would suggest you read this thoroughly: http://codex.wordpress.org/Using_Permalinks.
CITY is a single term w/i the taxonomy *cities*
EVENT is the post single
SITE_URL/cities/CITY
would yield a page of all EVENT posts in that CITYSITE_URL/cities/CITY/EVENT
to read a specific event in a specific cityIn your Settings -> Permalinks
administration panel select: "Post name" and save.
Then, go to your Ce Events -> Cities
admin screen.
hover over one of your terms (in my case new york city) and click view.
it should open up that term(city)'s list view and the url structure looks like so: http://wp.local/city/new-york-city/
if you need city
to read cities
, modify line 102 of the main plugin file i shared with you:
'rewrite' => array('slug' => 'city'),