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.
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?
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.
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.
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?
@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!
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.