WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using wp_insert_post in a loop to insert 500 posts in a new WP install. It works quickly, and memory usage is from 25M to 28M. The next run of a second batch of 500 posts, takes the memory from 25M to 178M. So the memory usage seems to be based on how many posts are already in the table. A third run of 500 posts exhausts the available memory. What is being stored to increase the memory that I can cleanup?

share|improve this question
up vote 0 down vote accepted

Did some profiling, it was the 5k+ queries being stored in the $wpdb->queries array.

share|improve this answer
That doesn’t really answer anything. Why are so many queries stored? How did you resolve that? – toscho Feb 28 '13 at 22:17
Unless SAVEQUERIES is defined as false, WP will save every query it makes in $wpdb->queries. I mentioned I was running 500+ inserts in a loop, that adds up to a lot of queries. Those queries take up space in memory as the loop progresses. – Poe Feb 28 '13 at 22:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.