Home › Forums › General Issues › Use Date/Time picker as post publication date › Reply To: Use Date/Time picker as post publication date
Hi John
Thanks for your reply.
There were two posts I found on acf about setting publication post date using acf date/time picker on the fontend. Another post I’ve found on stackexchange.
https://support.advancedcustomfields.com/forums/topic/set-post-publish-date-by-custom-field/
In any case – I have an acf form on the front end where the user creates a draft post. The form works fine and creates the draft post as required. However, I’d like to be able to include a date/time picker and have the selected date/time set as the post’s publication date. I tried using the following code but had no luck
function my_acf_save_post( $post_id ) {
$acfDate = get_field('post_date', $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);
Any ideas?
Thanks
P
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.