Wordpress - WP_Query leaking absurd amounts of memory

Excellent responses on WP Hackers: http://lists.automattic.com/pipermail/wp-hackers/2012-June/043213.html

What you're doing with that query, is loading EVERY matching post into memory, including the full post contents. As you can imagine, this is probably quite a lot of items.

You can pass 'fields' => 'ids' into WP_Query to simply return a list of matching post_ids instead, which should reduce the memory (and processing time) significantly:


Stumbled upon this while researching the memory issue pointed out here.

In this case, you can use get_the_id instead of using buffering to capture the id, and you could narrow the queried fields to only include ids.