WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

closed as too localized by toscho Mar 5 '13 at 23:39

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Can you please show us your code snippet for wp_insert_post? Thanks :) – Brian Fegter Feb 23 '12 at 20:51
It's pretty straightforward: //if a new story.... $post_id = wp_insert_post($article,true); add_post_meta($post_id, 'article_id', $article_id, true); – joey b Feb 23 '12 at 21:54
Do you mind copy/paste in your answer. I'd like to see what $article represents. – Brian Fegter Feb 23 '12 at 22:08
$article is just an array with information on the post. all the variables in it are populated with content that's was on the feed. $article = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_status', 'post_excerpt'); – joey b Feb 23 '12 at 22:14