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

Not much noticeable when working with individual posts, but when you create or delete multiple thousands in bulk and by code - process is quite slow.

Are there any good tweaks to apply and corners to cut?


  • wp_insert_post() with categories and tags passed;
  • add several custom fields;
  • create and associate attachments (from existing files).
share|improve this question
It would be interesting to profile this operation so we can study the bottlenecks. Measure before you optimize! – Jan Fabry Feb 17 '11 at 15:06
@Jan Fabry makes sense. I will try to setup a profiled test run after I am done with it. – Rarst Feb 17 '11 at 15:09
up vote 13 down vote accepted

When updating post taxonomies, you can call wp_defer_term_counting( true ) before you do your mass operation, and then wp_defer_term_counting( false ) to update the term counts only once per term.

share|improve this answer
Good one! I've seen this tweak mentioned, but completely forgot about it. – Rarst Feb 17 '11 at 15:10
nice one, never heard of it. you got my +1 – Bainternet Feb 17 '11 at 16:41

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.