Title: using wp_insert_post in a cron
Last modified: August 20, 2016

---

# using wp_insert_post in a cron

 *  [jebus](https://wordpress.org/support/users/jebus/)
 * (@jebus)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/using-wp_insert_post-in-a-cron/)
 * Hi all,
 * I’m trying to run a cron that grabs an XML feed and creates posts with it. First
   it loops through the XML data and creates an array item for each new post in 
   the feed.
 * After it’s gathered all those, it loops through the array and uses wp_insert_post()
   to add each one.
 * The problem is that this inevitably causes memory errors, or the mysql server
   to stop responding, or the cron script to otherwise die.
 * I’m watching the memory usage of the script, and it never gets above 64 megs.
   I have 256 allocated to PHP. I’m guessing this means the memory used by the wp_insert_post
   function is not included in this total.
 * I’ve tried to sleep() the cron for various amounts of time, but that doesn’t 
   work.
 * Is there a way to wait until wp_insert_post has completed and continue the cron
   script then? I’m assuming it returns the post id right away, and is not done 
   at that time.
 * Thanks.

The topic ‘using wp_insert_post in a cron’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [jebus](https://wordpress.org/support/users/jebus/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/using-wp_insert_post-in-a-cron/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
