Wordpress更新发布日期

时间:2014-04-11 12:33:11

标签: wordpress

当我从元框字段日期更新帖子发布日期时,它无法正常工作。我正在使用 save_post 挂钩,但它无法正常工作。 哪个函数用于更新发布日期。

我的代码:

// Update publisged date from date of launch for concept

function update_concept_post_date( $post_id ){

    if ( ! wp_is_post_revision( $post_id ) ){       

        $post_data = get_post($post_id);
       $date = get_post_meta($post_id, '_cmb_concept_signup_date', true);
        $updated_date = explode('-', $date);
        $new_date   =   date("Y-m-d h:i:s", mktime(0,0,0,$updated_date[1],$updated_date[2],$updated_date[0]));
      if($post_data->post_type == 'concepts'){
          $my_post = array(
              'ID'           => $post_id,
              'post_date' => $new_date
          );
          // update the post, which calls save_post again
          wp_update_post( $my_post );
      }
    }
}
add_action('save_post', 'update_concept_post_date', 10);

1 个答案:

答案 0 :(得分:1)

您正在解析日期错误,应该是;

$temp = explode(' ', $date);
$updated_date = explode('-', $temp[0]);

首先按空格字符解析,第一部分变为Y-m-d,然后按-解析此部分。

相关问题