• Hi,

    I have created a plugin that accesses an XML feed that contains articles and saves the articles from that feed as posts. You can set a time interval for the plugin to run via WP cron and access the feed to see if there is any new content. The plugin works and has worked on multiple sites, however, on this one site it’s hitting a snag.

    Each article on the feed has a id number. The way the plugin works, is when a new article is imported, the plugin grabs the id number associated with the article and saves it to the post_meta table. That way, on each subsequent run, the plugin looks to the postmeta table to see if the article id exists. If it doesn’t, it imports the article and creates a new post, if it does it doesn’t do anything.

    I’ve run into an issue where, when run via cron, the plugin isn’t saving the article id to the postmeta table, and as a result is creating duplicate articles. When run manually, everything works fine. I’ve narrowed down the issue to be the call to ‘wp_insert_post’. I make a call to ‘wp_insert_post’ to save the post, and expect it to return an post id number, but it doesn’t return anything.

    Upon further investigation, when run via cron, everything gets hung up in the wp_insert_post function in ‘post.php’. It makes it down to the call to ‘do_action(‘save_post’, $post_ID, $post);’. It enters the ‘_save_post_hook’ function, but doesn’t return. It just stops there, for some reason. No errors are being thrown and it looks like all the code in _save_post_hook is being executed.

    I have no idea why this is happening and don’t really know where to go from here, as I’ve spent days looking at this and don’t know what is going wrong.

    Any help is appreciated.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘wp_insert_post not completing when run via cron’ is closed to new replies.