• From the WP admin, I’m able to schedule posts to appear in the future, and wp-cron.php does it’s thing and updates post_status for those posts to ‘publish’.

    However, I’m writing an app that writes posts to the WP database outside of the WP admin. Nothing sinister, just a productivity booster ;o)

    So, when I write a future post to the database via my externel script, wp-cron.php just will not set this post to ‘publish’ at all. The post simply continues to sit in the DB with a post_status of ‘future’, and will not display on the site, even though the publish date has passed. And passed. And passed.

    I can’t for the life of me see why wp-cron.php works for posts that are entered through the admin, and WON’T work for posts that are entered via an external script – even though both posts have virtually identical entries in the DB.

    So, my question is: how does wp-cron.php work, and how can the script distinguish between posts that have been entered via the admin, and posts that have been entered by an external script, ‘cos I can’t tell the bleedin’ difference between ’em!!

    Anyone know??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter barrybell

    (@barrybell)

    (One thing to note is that I can post immediate entries to the DB (posts that already have a status of ‘publish’) via the external script and they show up in the blog as expected. So it’s not an issue with the external script as far as I can see.)

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    wp-cron doesn’t automatically run every so often to do magical tasks. You have to tell it to do those tasks.

    In other words, when you make a post using the admin pages, a task is added to WP-Cron that says “at this time, go set this post to publish”.

    You’re adding a post directly to the database, but you’re not adding a task for WP-Cron to find and act upon.

    Specifically, note this code in post.php:

    // Schedule publication.
    if ( 'future' == $post_status )
    	wp_schedule_single_event(strtotime($post_date_gmt. ' GMT'), 'publish_future_post', array($post_ID));

    See? It’s scheduling the event for wp-cron to act on later.

    The cron event data is stored as an array of stuff in the options table, with a key name of “cron”. So adding to it externally may be tricky.

    The way wp-cron works is that every time a page on the site is accessed, it checks that array in the database against the current time, and if any events have elapsed, it starts up a separate process to execute those events.

    Thread Starter barrybell

    (@barrybell)

    Excellent – just what I needed to know.

    Thanks!

    B

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘In-bloody-furiating!! wp-cron.php issue, I think.’ is closed to new replies.