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).
  • 1
    It would be interesting to profile this operation so we can study the bottlenecks. Measure before you optimize!
    – Jan Fabry
    Commented Feb 17, 2011 at 15:06
  • @Jan Fabry makes sense. I will try to setup a profiled test run after I am done with it.
    – Rarst
    Commented Feb 17, 2011 at 15:09

1 Answer 1


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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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