I’ve written a plugin which retrieves an xml file, parses and creates a series of short posts from the content.
Although each post is very short (sometimes just a single sentence, never more than a few sentences), there are around 1000 posts to create from the file.
Using wp_insert_post takes enough time for this job to timeout giving a 500 status.
I also encounter similar problems when deactivating the plugin and trying to move the same content.
Are there any quicker ways of populating (or removing) posts?
You can access the database with an INSERT statement and add multiple rows at once.
Something like this pseudo-code:
Make sure to fill all the values that are set to
NOT NULL
and have nodefault
value in the post table schema.From
wp-admin/includes/schema.php
:Also, regular posts need a default category. Not sure what happens if you omit that.
Not using the API might save you a minute now but cost you hours later. I have done similiar things and run into timeouts but not 500, you should realy check the php and appache logs first to try and find the cuase.