If you are using the ACF Custom Database Tables plugin and have opted to bypass core metadata storage, you’ll likely end up in a situation where you need to create a WP_Query based on data from your custom tables.
The basic approach here is to:
- Write some SQL that queries all post IDs matching your conditions, then;
- Pass an array of post IDs to the
This approach can result in significantly faster WP_Query queries when compared to using meta queries. I ran a few tests against a database containing 1 million records and I saw a 5-second meta query reduce to 1.3 seconds.
Writing your own SQL queries
Query helpers are something we have planned for a future release but at the time of writing, it’s necessary to put your SQL-writing hat on and write some very basic
If you haven’t written much SQL before, don’t worry. Basic SQL is really easy and you get the hang of it pretty quickly. If you want to learn the basics, check out our primer on using SQL in WordPress.
To get you started, I put together the Gist below. As always, if you run into any trouble and need help, we’re only a support request away.