Support » Fixing WordPress » How do I schedule a weekly cron event?

  • Resolved giant slayer


    I would like to schedule a post to be posted at 5:00pm CST each Friday.

    From looking at the WP-Cron functions, I see only options for hourly, daily, and twicedaily.

    I also found a filter that would allow a custom tim interval.

    // add custom time to cron
    function filter_cron_schedules( $param ) {
        return array( 'once_half_hour' => array(
                                    'interval' => 1800, // seconds
                                    'display'  => __( 'Once Half an Hour' )
                                ) );
    add_filter( 'cron_schedules', array( &$this, 'filter_cron_schedules' ) );

    I could find out how many seconds are in a week and place that value in the interval, but how would I tell it to start at the exact time I desire?

    Does anyone have any ideas on how to do a weekly event?


Viewing 5 replies - 1 through 5 (of 5 total)
  • I could not find anything within wordpress on this, but I have godaddy as my host and it has a cron scheduler.

    I created a cron event, but when the page is executed, php returns the following error.
    Fatal error: Call to undefined function wp_insert_post() in /home/content/g/i/a/giantslayer/html/wp-content/themes/slayer/free-weekly-test.php on line 15

    This is the code I am trying execute.

    $post_text='Testing Scheduler option for free weekly background.';
    $my_post = array(
        'comment_status' => 'open',
        'post_author' => 1,
        'post_category' => array(226) ,
        'post_content' => $post_text,
        'post_name' => 'Test',
        'post_status' => 'draft',
        'post_title' => 'Test',
        'post_type' => 'post',
        'tags_input' => 'free, weekly, photoshop, art, fine art'
    $new_post_id=wp_insert_post( $my_post );

    Is there something I need to do to see wordpress functions outside of wordpress?

    I have tried two things. I have tried to add the following code to my php to attempt to initialize wordpress.

    define('WP_USE_THEMES', true);
    /** Loads the WordPress Environment and Template */
    if ( !isset($wp_did_header) ) {
        $wp_did_header = true;
        require_once( dirname(__FILE__) . '/wp-load.php' );
        require_once( ABSPATH . WPINC . '/template-loader.php' );

    I was unable to load the required files.

    I then tried to move the file to the root directory, but when I try to load it, WordPress is already active and the file pulls a 404 not found error.

    Anyone have any ideas how I can get around either of these?
    Thanks, –christopher

    =) Sometimes I feel like I am talking to myself.

    Here is the error I am getting when trying to include wp-blog-header.php in my file.
    Warning: require() [function.require]: URL file-access is disabled in the server configuration in /home/content/g/i/a/giantslayer/html/wp-content/themes/slayer/wp-free-weekly-test.php on line 5

    anyone have any idea what this error means?

    Ok, I found the error was caused by using an absolute path. I changed the require statement to be as follows.

    I also found that this pulled a page that resulted in a wordpress generated page not found error. However, I did notice my desired script does execute and a new post is created. So I can schedule the cron event on my server at a weekly interval and use the line above to activate wordpress from the file I chose in my cron schedule.

    I then follow the above line with any code I desire for whatever weekly action I desire.

    How about simply making the post date 5PM on the following Friday. (OK, make it 4:59 for a slow host)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I schedule a weekly cron event?’ is closed to new replies.