Home › Forums › Front-end Issues › Schedule Post with Frontend Form? › Reply To: Schedule Post with Frontend Form?
I cannot manage to get this working whatsoever…. hopefully someone can assist. Perhaps things have changed in the last 8 years and there is a better way to do this?
Here’s my code to display my form:
<?php acf_form(array(
'post_id' => 'new_post',
'id' => 'new-email',
'new_post' => array(
'post_type' => 'emails',
'post_status' => 'future',
'field_groups' => array(1091),
'post_title' => true
),
'return' => '',
'submit_value' => 'Add new email'
)); ?>
Not sure if I have the field_groups ID correct or not. Not sure how to retrieve that. Is that the “post id” of the field group?
Here’s my functions file code:
add_filter('acf/pre_save_post' , 'emails_pre_save_post', 10, 1 );
function emails_pre_save_post($post_id) {
// check if this is to be a new post
if ($post_id != 'new_emails') {
return $post_id;
}
// The date picker field
// change field_563657f49b4d9 to the field key of your date field
$postdate = date('Y-m-d H:i:s', strtotime($_POST['acf']['field_emails_email_scheduled_date']));
// Create a new post
$post = array(
'post_type' => 'emails',
'post_title' => $_POST['acf']['_post_title'],
'post_status' => 'future',
'post_date' => $postdate,
'edit_date' => true
);
// insert the post
$post_id = wp_insert_post( $post );
// return the new ID
return $post_id;
}
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.