I have experience with building frontends with react.js that use external data from RESTful APIs (from a headless CMS).

Now I have someone ask me if I could build a wordpress website that has several stuff like default pages (using a page builder), certain landingpages, different custom post types for different purposes and an events calendar with an overview page and detail pages.

Everything except the events thingy should be built with wordpress stuff (like I said using a page builder, creating custom post types etc.).

The events calendar (or at least the data for the events calendar) should not take place in the wordpress database, though, as it is coming from and external RESTful API, based on its own database for the events-data. This database should remain the single source of truth. So importing everything into - for example an events-custom-post-type - is no consideration.

How would I go over this? I can imagine building page templates that call the API and build their HTML from that data (and maybe save responses in transients for caching etc.), but that would only work for the overview page, because I can create a WP-page called "Events Overview" and assign the page template to it. But how to create the detail pages? I would have to be able to call something like https://my-wp-site.com/events/{EVENT_ID_FROM_EXTERNAL_API} and since there is no wordpress page with that slug/id/whatever, it would give me a 404, right?

Even if I know how to fix that problem, what if the wordpress search should also take into consideration the events from that external api? If someone searches (with the wordpress-search) for something that is included in one of the events title or so, it would be expected to show up in the search results. That is one example of the data from the external api being mixed with the data of the wordpress database, but for sure there are many more examples that would cause a question mark to pop up in my head.

  • 1
    you wouldn't be able to get WP search to show events from the 3rd party API without using a 3rd party search solution, or syndicating that data into posts in WP. The easiest route for you is to add a rewrite rule to map everything under a certain URL to a single page, then load a react SPA on that page and do what you've always done. No need to complicate things further
    – Tom J Nowell
    Aug 20, 2021 at 13:32
  • Thanks for your answer. Can you clarify about the "syndicating that data into posts"? I'd love to go with your suggestion, but I would have to find a solution for the search-related stuff. Any suggestions on that? I've heard about algolia and elastic search, but I'm unsure if that would help me.
    – FbnKlmn
    Aug 23, 2021 at 6:42
  • 1
    Running cron jobs or code to pull the data in and create posts that represent it that can then be searched for, perhaps storing the original URL as meta then modifying their permalinks to use that meta via the post URL filter. That has downsides though, such as keeping things in sync etc. It's easier to use a dedicated search solution such as elastic or algolia then include your remote data in that index, but I don't have any resources I can share on those subjects. WP search is quite primitive.
    – Tom J Nowell
    Aug 23, 2021 at 10:56


Your Answer

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

Browse other questions tagged or ask your own question.