Title: wp_schedule_event &#8211; Creating PHP script
Last modified: August 18, 2016

---

# wp_schedule_event – Creating PHP script

 *  [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/)
 * Morning/Evening All.
 * I have written a small application that automatically inserts a number of posts
   straight into the wordpress database.
 * These are all inserted with an appropriate timestamp, at a given time every day
   for each of the posts I have inserted.
 * Now I understand for these posts to be set from a ‘future’ post to a posted post,
   then the time passes, I need to set up a entry in the wp_options table and can
   see the code, wp_schedule_event.
 * My problem is, I can’t work out how to use that function.
 * For example, I insert 70 posts, each having a time of 9am, and number 1 tommorow,
   number 2 tommorow, number 3 the next day etc.
 * Now these are all in the database, what I’m trying to do now is create a simple
   PHP script that goes through each of the post ID’s (I have these) and the time
   that it should be scheduled for (I also have these) but can’t for the life of
   me can’t get the script I have written to work.
 * Attached is a snipped to see if anything is wrong…
 *     ```
       <?PHP
       require_once('admin.php');
       wp_schedule_event(strtotime("Sat Apr 28 12:17:35 2007". " GMT"),'publish_future_post', array(10));
       wp_schedule_event(strtotime("Sat Apr 28 12:18:35 2007". " GMT"),'publish_future_post', array(11));
       ?>
       ```
   
 * This is uploaded to the wp_admin area and I run it, but nothing gets inserted.
 * My posts are all inserted with with ID’s from 10 to XX
 * Any help appreciated.

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/page/2/?output_format=md)

 *  Thread Starter [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-556946)
 * anyone help? :'(
 *  [Joe Hall](https://wordpress.org/support/users/redbmedia/)
 * (@redbmedia)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-556954)
 * I am actually working on the same type of application at the moment. Although
   going about it differently. I am writing a simple email script that can send 
   a message with my posting in it to WP using the “Post by Email” feature. I am
   automating the script using a cron job. I like this method because I don’t have
   to fool around with inserting data to the db. Instead I let WP do that for me.
   Below is an example of the script I am using:
 * >  ‘<?php
   >  $to = “SECRETEMAIL@mysite.com”; $subject = “POST TITLE”; $body = “
   > POST BODY/CONTENT”;
   > if (mail($to, $subject, $body)) {
   >  echo(“<p>Post successfully sent!</p>”); }
   > else { echo(“<p>Post delivery failed.</p>”); } ?>’
 * The only problem that I am having is setting up my POP3 server to work well with
   WP. Hope this helps.
 *  Thread Starter [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557061)
 * Hmm interesting, how do you specify posts that start in the future, like the 
   date and time etc?
 *  [Joe Hall](https://wordpress.org/support/users/redbmedia/)
 * (@redbmedia)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557087)
 * I don’t. When I want the post to start posting I start the cron job. When I want
   it to stop posting I just delete the script and then the cron. If you want to
   automate a time and a date to publish a posting, WP already has a feature for
   that build in.
 * My application is just for those that want a posting to conitually republished
   over and over again at designated intervals.
 *  Thread Starter [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557135)
 * yeah thats the whole point!
 * I have 70-150 articles to post, one a day for the next X days, I can insert them
   into the database fine, as long as I want them to appear all at once. I can also
   set them all to a future date, but cannot work out how to schedule the CRON job
   using wp_schedule_event!
 * If anyone can help with this, would be much appreciated!
 * Thanks,
    Steve
 *  [Joe Hall](https://wordpress.org/support/users/redbmedia/)
 * (@redbmedia)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557157)
 * “I can also set them all to a future date,”
 * If you can do this, then why do you need the cron job?
 *  Thread Starter [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557159)
 * because just setting them to a future date is not enough to actually register
   them in the pseudo-cron job.
 * when you post (via the new post screen) with a future date entered, and the modify
   timestamp flag ticked, it enters the date in the posts database (with the future
   date) and also registers an entry in another table to tell wordpress, that on
   a given date and time, set this posts status from ‘Future’ to ‘Published’
 * Now I can do the first bit OK but can’t get the second (cron bit) working!
 * If anyone can take a look at the PHP and see what I am doing wrong it would be
   appreciated 🙂
 * Thanks,
    Steve
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557163)
 * You should just do it like this. It’s not difficult:
 * `wp_schedule_single_event($time_goes_here, 'publish_future_post', array($your_post_ID_goes_here));`
 * Done and done. It will set their post status from future to published at whatever
   time you want.
 * You won’t be requiring admin.php, mind you. Best way to do it is like this:
 *     ```
       <?php
       require('/path/to/your/blog/wp_blog_header.php');
       wp_schedule_single_event($time_goes_here, 'publish_future_post', array($your_post_ID_goes_here));
       ...more...
       ?>
       ```
   
 * And then run that manually, just once.
 *  Thread Starter [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557165)
 * thanks mate, will try that out!
 * Rgds,
    Steve
 *  Thread Starter [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557166)
 * Couple of Q’s for you if you have a sec!
 * I assume that $time_goes_here would work with the response from `strtotime("Tue
   May 1 02:14:05 2007")`
 * Also the array($your_post_ID_goes_here) can that be literally
 * array(array(10)) if my ID is 10? What else needs to go in that array??
 * Cheers
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557172)
 * > _I assume that $time\_goes\_here would work with the response from strtotime(“
   > Tue May 1 02:14:05 2007”)_
 * Sure.
 * > _Also the array($your\_post\_ID\_goes\_here) can that be literally array(array(
   > 10)) if my ID is 10? What else needs to go in that array??_
 * No. It would be just array(10). You’re overcomplicating things.
 * `wp_schedule_single_event(strtotime("Tue May 1 02:14:05 2007 GMT"), 'publish_future_post',
   array(10));`
 *  Thread Starter [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557201)
 * Hmm, thanks for the help, but no joy.
 * I’ve created the script, checked the dates that I’m entering (all OK) and I print
   out a message before and after the wp_schedule_event call. (all seems OK)
 * but nothing gets entered into the database. It’s as if the call to wp_schedule_event
   is being ignored.
 * Anyway to check by switching on Debug or trace??
 *  Thread Starter [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [19 years ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557207)
 * anyone help? still stuck with this one 🙁
 *  Thread Starter [wtd](https://wordpress.org/support/users/wtd/)
 * (@wtd)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557216)
 * still no joy :'(
 *  [asido](https://wordpress.org/support/users/asido/)
 * (@asido)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/#post-557217)
 * Hi mate,
 * Check this out:
    [http://blog.slaven.net.au/archives/2007/02/01/timing-is-everything-scheduling-in-wordpress/](http://blog.slaven.net.au/archives/2007/02/01/timing-is-everything-scheduling-in-wordpress/)
 * By reading the thread so far, I guess the event does not get fired because you
   did nto turn it into a plugin hook. Check the section titled “Defining the event
   you’re scheduling”, you will see that there is an example of what needs to be
   done.
 * I really hope this helps your case. Good luck, mate!

Viewing 15 replies - 1 through 15 (of 17 total)

1 [2](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/page/2/?output_format=md)

The topic ‘wp_schedule_event – Creating PHP script’ is closed to new replies.

## Tags

 * [cron](https://wordpress.org/support/topic-tag/cron/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [wp_schedule_event](https://wordpress.org/support/topic-tag/wp_schedule_event/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 17 replies
 * 5 participants
 * Last reply from: [wtd](https://wordpress.org/support/users/wtd/)
 * Last activity: [18 years, 10 months ago](https://wordpress.org/support/topic/wp_schedule_event-creating-php-script/page/2/#post-557220)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
