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

custom post types - Changing wordpress publication date to ACF date and time picker date not working

programmeradmin7浏览0评论

This might be a long post but I want to explain in detail what I'm trying to do and what I've already done.

I'm making custom forms using the advanced custom fields plugin and I need to display these custom forms in a calendar. So I'm using the plugin WP fullcalendar for that, it works but instead, it displays on the posts published date not the date I chose w the date and time picker.

In the support forums for the plugin, I followed this / but to no avail and instead everything is blank on the calendar for me.

So I thought maybe I could change the publication date of the post so that it can display at the correct time. I found this code here / (you need to scroll towards the bottom to get to the code)

And I need only a certain post types pub date to be changed. Please know that I am a novice at PHP and had to learn it very recently on the spot so I'm not confident at all in what I've done or how to implement the code. (I added the code to the functions.php file)

if( get_post_type() == 'cpost2' ) {
    add_action('acf/save_post', 'change_pub_date', 20);
    function change_pub_date($post_id) {
        // remove this filter to prevent potential infinite loop
        remove_filter('acf/save_post', 'change_pub_date', 20);
        // date format must be "Y-m-d H:i:s"
        $post_date = get_field('post_date');
        $post = wp_update_post(array(
            'ID' => $post_id,
            'post_date' => $post_date));
}
} else {
    return false;
}

From add action to the post_date bit is the code from the second link, but it doesn't change anything.

Any help would be very much appreciated!!

发布评论

评论列表(0)

  1. 暂无评论