Title: Calling WordPress functions from third party script
Last modified: August 18, 2016

---

# Calling WordPress functions from third party script

 *  [pickledegg](https://wordpress.org/support/users/pickledegg/)
 * (@pickledegg)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-third-party-script/)
 * I have a script that loops through a database full of articles and posts them
   into the wordpress database structure. I’ve figured I need to call wordpress 
   functionality to add the scheduled posts to the cron array. I need to do this
   as they just sit there as future posts otherwise, even after the post timestamp
   elapses.
 * So, I assume in order to do this I have to call:
 *     ```
       wp_clear_scheduled_hook( 'publish_future_post', $post->ID );
       	wp_schedule_single_event(strtotime($post->post_date_gmt. ' GMT'), 'publish_future_post', array($post->ID));
       ```
   
 * But I’m unsure what I have to put in my script to call these, and where in the
   wordpress file structure I have to put the script.
 * Can anyone understand what I’m trying to do, and can anyone offer any help? Many
   thanks.
 * If its plugin territory, thats fine, but I’ve never written a plugin before.

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 6 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-third-party-script/#post-660475)
 * You need to add this to your script at the very top:
    `require('./path/to/wp-
   blog-header.php');`
 * Where you put your script doesn’t matter, just make that above path correct relatively,
   so that it can find the main WordPress wp-blog-header.php file.
 *  Thread Starter [pickledegg](https://wordpress.org/support/users/pickledegg/)
 * (@pickledegg)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-third-party-script/#post-660522)
 * Can you explain why I need to do that? And are you saying that if I put the code
   in my first post, and pass it my post ID, it will work?
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 6 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-third-party-script/#post-660541)
 * You include that line so that your script includes all the WordPress code. The`
   wp_*` functions won’t be defined unless you include WordPress’s code.
 * As for whether it will work, that depends on what you mean by “work”. Will the
   functions be available to you to use? Yes. Will that code do what you think it
   does? I don’t really know that, I don’t much understand what you’re trying to
   do.
 *  Thread Starter [pickledegg](https://wordpress.org/support/users/pickledegg/)
 * (@pickledegg)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-third-party-script/#post-660723)
 * Hi Otto,
 * Well its adding arrays to the cron record in the options table, but my posts 
   are still not displaying.
 * Right, you say you don’t follow what I’m trying to do:
 * I have a database full of articles that I’ve collected, from a paid source. I’m
   trying to write a script that loops through my database and inserts the relevant
   entries into the wordpress database tables, in order to ‘fool’ wordpress into
   thinking that I’ve posted them manually. I can achieve this if I post them all
   to go live, but what I am trying to do is schedule them at a rate of 5 a day 
   for several months.
 * I’ve inserted the dates in the correct format, but I’ve discovered I need to 
   add timestamps etc to the cron value in the options table. I initially tried 
   to decipher the arrays and came unstuck when I found that there was a md5 hash
   in there, so I’m now trying to call the correct WP functions that would insert
   the cron job array for me. I thought I’d cracked it as what you suggested works
   as far as calling the WP functions, but still my posts are not showing, so I 
   must be missing something else.
 * Do you see where I’m at? Do you now exactly what wordpress does in order to schedule
   a post? I’m considering setting up a debugger.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 6 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-third-party-script/#post-660733)
 * Well, you’ve got the right code to schedule the future post, but your WP-Cron
   may not be working due to a server misconfiguration. Does a future post work 
   if you do it normally?
 *  [dcoops](https://wordpress.org/support/users/dcoops/)
 * (@dcoops)
 * [18 years, 6 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-third-party-script/#post-660767)
 * [@pickledegg](https://wordpress.org/support/users/pickledegg/): I’m in exactly
   the same situation as you. Glad you are a step ahead of me!
 * Please keep your updates in here, I really want to know how it’s done!
 *  Thread Starter [pickledegg](https://wordpress.org/support/users/pickledegg/)
 * (@pickledegg)
 * [18 years, 5 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-third-party-script/#post-660803)
 * Right, I’m going to strip the wordpress back a bit, and do some experiments with
   a single future post.
 * > Does a future post work if you do it normally?
 * I’ll let you know.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Calling WordPress functions from third party script’ is closed to new
replies.

 * 7 replies
 * 3 participants
 * Last reply from: [pickledegg](https://wordpress.org/support/users/pickledegg/)
 * Last activity: [18 years, 5 months ago](https://wordpress.org/support/topic/calling-wordpress-functions-from-third-party-script/#post-660803)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
