如何设置未来/旧日期发布?

时间:2013-09-25 07:27:12

标签: php wordpress

我在WordPress中有帖子属于第13类, 我想将帖子的日期替换为将来或旧日期。

示例我发布了2012年12月31日创建的新闻,我想将此日期替换为01/01/2014我该怎么做?

WordPress中的哪些功能可以帮助我,或者这属于PhpMyAdmin? 我很乐意为如何解决这个问题找到方向

非常感谢你的帮助。

我找到了这段代码:

function bulk_schedule_posts_wpse_105834() {
  $args = (
    array(
      'cat' => 1,
      'posts_per_page' => -1,
      'post_status' => 'draft',
      'post_type' => 'post',
    )
  );
  $posts = new WP_Query($args);
  if (!$posts->have_posts()) return false;

  $date = '2013-08-01';
  $times = array(
    '10:00',
    '14:00',
    '17:00',
    '20:30'
  );

  while ($posts->have_posts()) {

    global $post;
    $posts->the_post();

    if (0 !== $posts->current_post && 0 === $posts->current_post%4) {
      $date = date('Y-m-d',strtotime('+1 day',strtotime($date)));
    }

    $thisdate = $date.' '.$times[$posts->current_post%4].':00';
    $date_gmt = get_gmt_from_date($thisdate);
    $post->edit_date = true;
    $post->post_date = $thisdate;
    $post->post_date_gmt = $date_gmt;
    $post->post_status = 'future';

    wp_update_post($post);
  }
}
bulk_schedule_posts_wpse_105834();  

1 个答案:

答案 0 :(得分:1)

我不确定这是编码问题,您可以在管理面板中设置wordpress中任何帖子的日期 - 您应该在发布或更新之前看到该选项。

enter image description here

是的,你可以通过phpMyAdmin从'wp_posts'表中更改帖子的日期,如果你真的需要的话。

enter image description here