I'm working on a plugin which has bulk post inserts using a spreadsheet. This spreadsheet can have multiple thousand rows, each row corresponding to a post. I'm parsing this spreadsheet, looping over the parsed data and using wp_insert_post to insert the posts. I noticed that when I used a spreadsheet with around 2000 entries, only around 600 posts were inserted.

Is there a limit on the number of wp_insert_post calls in one shot? Or could it be a limit on one shot mysql inserts?

(edited title for more clarity)

  • 1
    Wicked problem! I can't see wp_insert_post being the culprit, as it doesn't keep track on how many iterations it's gone through in a given timeframe. I can't see mySQL being the issue, as it doesn't have a limit for maximum queries, just one for maximum size of one query (see max_allowed_packet). Is it always exactly 670 successful inserts? If so, have you tried removing the 671st row from the spreadsheet, to check whether it depends on the data? Also, have you had the loop return number of iterations? Does it finish? – Johannes Pille Nov 15 '11 at 7:20
  • I haven't tried removing the 671st row, maybe I should try these things and get back... – Rutwick Gangurde Nov 15 '11 at 8:04

Something tells me that it could be the maximum script execution timing out perhaps. The amount of memory your inserts are consuming could also be the culprit. Are you getting any error messages, blank screens or anything like that?

You could try adding the following above where you're calling the wp_insert_post() function:

  • Thanks for the reply! No errors, blank screens or anything as such. Just 670 out of 2000 entries entered! – Rutwick Gangurde Nov 15 '11 at 6:28
  • I tried same script locally, and it worked fine for all the 2478 entries. I guess time out could be an issue. Accepting your answer. – Rutwick Gangurde Nov 21 '11 at 14:30
  • Thanks for accepting. For your local issue, try putting this right at the top of the script doing the bulk inserting and see if anything changes. ini_set('max_execution_time', 300); //300 seconds = 5 minutes – Dwayne Charrington Nov 22 '11 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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