I suggest to not merge any extra database with WordPress one since it might not be good for security but if you don’t have any other option than you can just write custom mysql query using standard php mysqli functions.
If you have 10,000+ pages than you should not use WordPress for this type of setup, you should separate WordPress and your other application.
Thanks a lot for the reply.
I have written custom queries to get the data etc., but I worry about performance if I cannot enable caching somehow.
So what I’m looking for is a way to enable caching for all these non-WP pages, preferably through a WP caching plugin (for example one that caches pages based on crawling instead of the sitemap).
Why not trick WP into it?
Hear me out 🙂
WordPress can output more than just WordPress data, so if you instead of filtering the 404 were to use query variables and rewrite rule, then you could do this:
1. Make a PHP interface to safely output your custom content (think of it like a shortcode for a moment)
2. Make a page called /your-custom-whatever/
and have it output what you built in 1
3. Use https://developer.wordpress.org/reference/functions/add_rewrite_rule/ to generate the subpages
That would allow static cache plugins (w3tc, wp super cache, WP Rocket, etc) to create caches.
It would also allow dynamic cache integration plugins (like ones that tell your proxy cache like cloudflare to delete a cached file) to properly talk to the services.
There are other options, of course, but making a page be generated by WP will give you the ability to use WP solutions.
If you weren’t going that route, I’d recommend something else like static HTML, and the files themselves would always take precedence over WP generated content.
Nice approach. Didn’t know of add_rewrite_rule()
You could use a CDN like Cloudflare for caching.