当发布日期为30天时自动更改发布日期

时间:2016-08-31 作者:ria

我正在使用下面的代码,但不工作。请告诉我是否有其他方法或我在哪里犯错?

//cron work
function isa_add_every_minutes( $schedules ) {

    $schedules[\'every_minutes\'] = array(
            \'interval\'  => 60,
            \'display\'   => __( \'Every 1 Minutes\', \'textdomain\' )
    );

    return $schedules;
}
add_filter( \'cron_schedules\', \'isa_add_every_minutes\' );

// Add function to register event to WordPress init
add_action( \'init\', \'register_event\');

// Function which will register the event
function register_event() {

    // Make sure this event hasn\'t been scheduled
    if( !wp_next_scheduled( \'post_status_change\' ) ) {
        // Schedule the event
        wp_schedule_event( time(), \'every_minutes\', \'post_status_change\' );
    }
}

add_action( \'post_status_change\', \'post_status_change_all\' );

// This function will run once the \'delete_post_revisions\' is called
function post_status_change_all() {

 global $wpdb;
  $daystogo = "5";
  $sql = "UPDATE wp_posts SET post_status = \'draft\' WHERE post_type = \'post\' AND DATEDIFF(NOW(), post_date) > \'$daystogo\')";
  echo $sql;
  $wpdb->query( $sql );
}
谢谢。。

1 个回复
SO网友:ria

现在这个问题已经解决了。我已添加:\'date_default_timezone_set(\'Asia/Calcutta\'); \'出现了时间错误。现在,我错了。

相关推荐