I've a site that uses just about a bazillion complex loops...in many instances. For many said loops, I found myself using
WP_Query to create an array only to use another
WP_Query ad-almost-infinitum to render a very 'filtered-down' end loop. I have the Query Monitor Plugin enabled and the amount of query requests would make anyone that cares about query performance blush...a lot. My end goal: render complex loops fast whilst minimizing database requests.
Note: I've peeked into, but I've not yet had the time to fully delve-into/test/verify WP's Rest API. I also have various caching mechanisms in place
So, what I've done is use
WP_Query in conjunction with cron jobs (I have a server cron job, in ~/wp-config.php if have
define('DISABLE_WP_CRON', true); set) in order to create static JSON files that update every x (30 mins) intervals.
From there I'm using something a la...
$file = get_home_path() . '/my-dir/my-stuff.json'; $my_json_list = json_decode(file_get_contents($file), true);
...to get a loop for
- Does what I'm doing make any sense?
- Is there a better way to render complex loops, whilst minimizing database requests?
Huge thanks in advance!