Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Context:

  • wp_insert_post() with categories and tags passed;
  • add several custom fields;
  • create and associate attachments (from existing files).
share|improve this question
1  
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
add comment

1 Answer

up vote 6 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
add comment

Your Answer

 
discard

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.