I am having a huge argument with Wordpress, and this is my last port of call before I throw the PC out of the window.

I have a plugin here that exports an XML feed into Wordpress posts. The posts have an image which is saved locally, the HTML to display the image is then inserted at the beginning of the post content, before being inserted into Wordpress using wp_insert_post.

I'm having a slight issue though. The script works fine when it is turned on manually. But as soon as it triggered by cron, the post will import fine, but the image will not save locally, and the HTML for the image is not present in the posts content.

I really am at a loose end. I thought it was to do with permissions, and the fact that the posts were being imported with no author. I then changed it so they were marked as written by an admin, but that made no difference.

What is the problem of running it via cron vs running it manually when logged in?

If anyone can help solve this then I will be eternally grateful!

  • 1
    What does the function that runs on wp_insert_post look like?
    – tollmanz
    Commented Jul 12, 2011 at 14:51
  • WP Cron problems are hard to debug, so take a deep breath first. Maybe the image import is done via AJAX which does not work in cron? Are you using a specific plugin? If so, please reference.
    – hakre
    Commented Jul 12, 2011 at 14:56
  • The images are simply downloaded to the server using PHP fopen.
    – Danny
    Commented Jul 12, 2011 at 15:37
  • Furthermore, it's not a specific plugin, just one that was developed inhouse by us. But we are stumped. It's also stopped functioning on the latest Wordpress (3.2), but it works on 2.8.6, but that's a whole other story.
    – Danny
    Commented Jul 12, 2011 at 15:38
  • I think the main issue here is it works completely when it is activated, so it must be something that's not accessible from cron, but it's identifying what.
    – Danny
    Commented Jul 12, 2011 at 15:39

1 Answer 1


Ok, so it turns out the solution is slightly embarrassing on my part and I couldn't see the forest for the trees.

The code that was executed by the cron job was trying to check the contents of a variable that is set via a radio button on the admin / plugin activation page.

Thus, the part of the code to save the image (inside an if statement) was not being accessed.

It just goes to show how much of an issue a small error can become when there's no access to any error logs or outputs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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