Changing wordpress publication date to ACF date and time picker date not working


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!!

, , , , pops0903 12 months 2020-08-07T18:10:34-05:00 0 Answers 56 views 0

Leave an answer