Home › Forums › Front-end Issues › How do the date of publication by a front-end form? › Reply To: How do the date of publication by a front-end form?
Hi @buylov
Maybe you can use something like this:
function my_pre_save_post( $post_id ) {
// check if this is to be a new post
if( $post_id != 'new' ) {
return $post_id
}
$posted_date = $_POST['acf']['field_1234567890'];
$theDate = date_create_from_format('Ymd', $posted_date);
$theDate = date_format($theDate, 'Y-m-d H:i:s');
// Create a new post
$args = array(
'post_status' => 'publish' ,
'post_type' => 'post' ,
'post_date' => $theDate ,
);
// insert the post
$post_id = wp_insert_post( $args );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
where field_1234567890 is your date field key. Keep in mind that I haven’t tested it yet.
Hope this helps.
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.