I would like to generate dynamic pages based on a third-party API. However, I'm not sure where in the WP loop to capture the request and generate the content. For example, if a user is requesting a page at
I would like to detect that they are requesting an event page by looking at the URL slug, then using the final piece, "june-2", to make a request to the third-party API and use the data to generate a page. Unfortunately, I can't figure out where to place it before a 404 is generated. I have tried the theme's index.php and page.php files. Would it better to do this with URL rewriting?