最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Set post publish date by custom field

programmeradmin2浏览0评论

I created custom fields with ACF to define a new date for my post on wordpress. I then created this function that updates the date with my custom field and works when I update a post.

// Save ACF custom field to date-time post
function my_acf_save_post( $post_id ) {
    $acfDate = get_field('data_time_post', $post_id);
    //Test if you receive the data field correctly:
    //echo $acfDate;
    //exit (-1);
    $my_post = array();
    $my_post['ID'] = $post_id;
    $my_post['post_date'] = $acfDate;
    wp_update_post ( $my_post );
}
add_action('acf/save_post', 'my_acf_save_post', 20);

But it doesn't work when I create a new post, only whn update

I think the problem is this function: wp_update_post

Thank you all.

发布评论

评论列表(0)

  1. 暂无评论