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
You still need the acf_form() in the templates and this code in the functions.php file.
Also, you need to pass the post title and post content. It should be 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 ,
'post_title' => $_POST['acf']['_post_title'] ,
'post_content' => $_POST['acf']['_post_content'] ,
);
// 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 );
I 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.