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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0