WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to run a PHP script through real cron (WP cron being too unreliable). Within that script, I need $wpdb to insert data into WordPress table. But of course $wpdb will not be available as WordPress would not be initialized. Right? So, my question is how to 'include' WordPress/initialize WordPress environment to do such tasks? How about require_once("wp-load.php")?

share|improve this question
up vote 2 down vote accepted

You can use real cron to trigger WP cron - by fetching wp-cron.php file from root (snippet from quick google search).

That will take care of environment and everything.

share|improve this answer
Thanks! I hope this will also work when we have active cache plugins. Right? See – afnrf Jul 25 '11 at 12:50
@Affan it completely should. The problem with caching plugins is triggering cron, WP cron file itself it not part of site's front-end and should not be affected by caching plugin. – Rarst Jul 25 '11 at 12:55

If you want to trigger any script via cron you can also skip wp-cron (limited functionality anyway) and cron the script directly.

The script have to load the wordpress environment itself if it wants to use wordpress functionality.

A solution to this can be found here : Initialize WordPress environment to use in command line script

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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