How to create connection among state, city, store and store number based on URL
-
21-04-2021 - |
Question
I'm about creating a store in which I have state, city, store, and store number, so what is the best way to create a connection among them? Is that okay if I create CPT with name store then create taxonomy state, city and store number? actually, i also want the URL should be like
example.com/state/city/store-numebr/store
i.e
example.come/alabama/muscleshoals/8042788/liberty-tax-al-muscle-shoals
so what's the best way to create relations which help me create the same URL above?
Solution
I would say you already have the answer. The thing I would recommend is to create a CPT called Store. That will give you the capability of having something like:
example.com/store/store-name
Being store
the name of your CPT.
Now with the taxonomy:
First approach: Just one taxonomy
Now, you would create a custom taxonomy for the CPT, maybe called store_category
and have the states, cities and store numbers being created as terms under this category, hierarchically.
The problem with this approach is that creating the permalink structure will be difficult since there is no way to specify a top level or second level term inside the permalink. So I would opt for the second approach.
Second Approach: multiple Taxonomies
I would create one taxonomy called state
, one called city
and one called store_number
. This may seem overhead but this will give you a logic separation between one type of taxonomy and the other. Once this is ready, now you would only need to hack
the permalinks for this CPT to get the url structure you are looking for.
In general, you now should have the capability to define a permalink structure like:
example.com/%state%/%city%/%store_number%/%post_name%
This could be achieve with a plugin like Custom Post Type Permalinks Custom Post Type Permalinks
I think this is the best way to get this relationship going.