自定义日期后1天将发布状态更改为草稿

时间:2018-06-07 作者:Mathias

1天后koncerter_start_date具有自定义帖子类型的所有帖子koncert必须获得状态草稿

1 个回复
最合适的回答,由SO网友:Bjorn 整理而成

你的问题不是很清楚。

你的意思是:

1天后koncerter_start_date 具有自定义帖子类型的所有帖子koncert 必须获取状态draft?

<小时>

EDIT

代码:

add_action( \'wp_loaded\', \'concert_daily_tasks\' );
function concert_daily_tasks() {
  $current_url = "https://" . $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'];
  if ( $current_url == \'https://example.com/concert-daily-tasks\' ) { // <-- set the correct URL!
    check_concert_status();
  }
}

function check_concert_status() {
  $today = new DateTime();

  $concert_start_date_str = \'2018-10-10\'; // I\'m not sure where/how you get this data.
  $concert_start_date = DateTime::createFromFormat(\'Y-m-d\', $concert_start_date_str); // make sure the format (\'Y-m-d\') matches $concert_start_date_str

  if($concert_start_date) {
    if($concert_start_date->modify(\'+1 day\') <= $today) { // if concert start day was yesterday (or older) continue
      $args = array(
        \'posts_per_page\'   => -1, // get all posts
        \'post_type\'        => \'koncert\',
        \'post_status\'      => \'publish\',
      );
      $posts = get_posts($args);
      if($posts) {
        foreach($posts as $post) {
          wp_update_post(array(
            \'ID\' => $post->ID,
            \'post_status\' => \'draft\',
          ));
        }
      }
    }
  }
}
Important:

完成$concert\\u start\\u date\\u str集合,请参阅脚本https://example.com/concert-daily-tasks 代码将运行。您可能可以在主机面板中设置acron作业计划

结束

相关推荐

Only Showing Upcoming Events

在此页面的侧栏中:http://lifebridgecypress.org/our-people, 我有一个即将使用此代码的事件列表。。。<ul id=\"upcoming-events\"> <?php $latestPosts = new WP_Query(); $latestPosts->query(\'cat=3&showposts=10\'); ?> <?php while ($latestPos