Site icon Hip-Hop Website Design and Development

Design idea for custom post type with sections

Intro:

This is my first time working with wordpress, that’s I why I would love to get some inspiration from other wordpress developers on this topic. Probably I’m overlooking an obvious solution. I’m using WordPress Version 5.8.3

The task:

I’m building a site, that mainly revolves around events, many of them. I built a plugin with a custom post type for events. Every event is different and every event post will be filled with lots of content (text, images, videos, documents). Some of this content can be bundled together in sections by country. I want to use Gutenberg and I would love to have meaningfull slugs. Ideally the following slugs would be possible:

1. event:

site.com/events/an-awesome-event/
-> this shows the main event post but only links to the sections

site.com/events/an-awesome-event/countries/
-> this shows the content of all country related sections for this 1. event  

site.com/events/an-awesome-event/countries/austria
-> this shows the content of the section that is related to austria for 1. event

2. event:

site.com/events/a-different-and-exhausting-event/
-> this shows the main event post for 2. event

site.com/events/a-different-and-exhausting-event/countries/
-> this shows the content of all country related sections for 2. event 

site.com/events/a-different-and-exhausting-event/countries/austria
-> this shows the content of the section that is related to austria for 2. event

The question:

What could be the smartest way to achieve this?

My ideas:

1. Idea: Use a second custom post type, for example sections and build a Gutenberg plugin that makes it possible to link to those section posts from the event post.

Problem: Since there are many events in the end there will be, for example hundreds of sections titled Austria (for different events) and so on. So ideally the slug for a section would be appended to an event as above. But how? With custom rewrite_rules? And is this a good approach, or way to hacky / complicated. Also it could get quite complicated to browse this structure in the editor.

2. Idea: Build a custom Gutenberg plugin that uses <InnerBlocks /> and is assigned a country related attribute. All the section content is placed inside this <InnerBlocks />. Then pass a query parameter like ?country=austria to the single-event.php that handles rendering of the event content. Finally filter out the blocks that should be rendered by adding a filter to render_block hook.

Problem: Filtering works partly, but there seems to be no way to tell straight away if a block is a nested block. So i would have to store some additional information in a $_REQUEST variable to make this possible. This also seems to be quite hacky / and maybe even has some serious pitfalls, that I’m not seeing right now..

So that’s where I’m at right now. I can think of two ways to hack my way through, but I’m hoping that someone can point me in the direction of a much more simple solution!