1

I am trying to work out the most sensible way to structure a new site. I would like to have continents, countries and articles. Articles will be the normal post type but I am unsure of the best way to setup the continents and countries.

I have played with setting up two new post types continent and country and have added a meta box to allow the country to associate itself with a continent. The URL structure is also what I want: /custom/continent/country The trouble is how to efficiently associate posts to a country so that they can be queried at the continent and country level.

The other option I am trying is to setup two taxonomies, which is easier in terms of categorising the posts, but makes URL rewriting a pain. I'd also want to limit the post to being tagged with multiple continents and countries.

The posts will just use a regular permalink structure for now.

UPDATE: I am looking for a solution that does not use plugins please. I can already create custom post types or custom taxonomies.

3
  • I would check out the excellent Posts 2 Posts plugin if you haven't already. Makes connecting posts of different types and querying them a breeze. Dec 29, 2016 at 19:24
  • Thanks, I did look at that plugin but it hasn't been updated in over a year and I prefer to write my own. Dec 29, 2016 at 21:14
  • I would suggest looking at the code of that plugin then and seeing how it works. The original author wrote a lot of the WP core query code and it is focused on efficiency. And regarding I'd also want to limit the post to being tagged with multiple continents and countries, you can use taxonomies and implement your own UI with a meta box.
    – Milo
    Dec 30, 2016 at 0:25

1 Answer 1

0

CPTUI and add_rewrite_endpoint will help you get the desired things.

[Update] From my comment-

You need pairs for rewrite rule /base/1 or base/1/base2/2 using wordpress rewriting... and the way you want will not be that easy depending on wordpress. If you have fixed /custom/continent/country structure then add HTACCESS of your own as site/1/2/3 to yield site/?continent=1&country=2&article=3. This will create global variable in wordpress environment to be queried anytime... :) Hope this helps.

7
  • Thanks for your answer. I've updated my question as I want to avoid using plugins. Mainly so that I can learn, but also because I won't use 90% of the plugin functionality and want to keep the site as lightweight as possible. Dec 30, 2016 at 11:54
  • You can do it without using any sort of plugin. And I can bet by the time you finish learning you will find your question very simple to answer. Dec 30, 2016 at 12:46
  • I will share the answer if I figure it out myself, but I was hoping to find some help here ;) Dec 30, 2016 at 14:12
  • I guess you need pairs for rewrite rule /base/1 or base/1/base/2 using wordpress rewriting... and the way you want will not be that easy depending on wordpress. If you have fixed /custom/continent/country structure then add HTACCESS of your own as site/1/2/3 to yield site/?continent=1&country=2&article=3. This will create global variable in wordpress environment to be queried anytime... :) Hope this helps. Dec 30, 2016 at 14:43
  • That last part is actually very helpful. It would mean I could have articles nested under a continent/country/article-slug which may be nice for SEO purposes. I think I now need to focus on how to link posts to a country, and how to create templates and queries to display posts on a country page, and on a continent page. Thanks Dec 30, 2016 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.