Hello I’m having a very annoying issue with front end posting, the form is always pre-populated with the last posted values, I’ve tried autofilled =’off’ attribute and it still doesn’t work, when I change “post_id = ‘new’ to ‘new_post’ it works but the title dosen’t get insert in the database anymore, i’m using the latest acf pro,any idea? Here’s the front end code from a tutorial, thank you:
add_action( 'genesis_entry_content', 'tsm_do_create_post_form' );
function tsm_do_create_post_form() {
// Bail if not logged in or able to post
if ( ! ( is_user_logged_in()|| current_user_can('publish_posts') ) ) {
echo 'You must be a registered author to post.
';
return;
}
$new_post = array(
'post_id' => 'new', // Create a new post
// PUT IN YOUR OWN FIELD GROUP ID(s)
'field_groups' => array(00000), // Create post field group ID(s)
'form' => true,
'return' => '%post_url%', // Redirect to new post url
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => 'Submit Post',
'updated_message' => 'Saved!'
);
acf_form( $new_post );
}
add_filter('acf/pre_save_post' , 'tsm_do_pre_save_post' );
function tsm_do_pre_save_post( $post_id ) {
// Bail if not logged in or not able to post
if ( ! ( is_user_logged_in() || current_user_can('publish_posts') ) ) {
return;
}
// check if this is to be a new post
if( $post_id != 'new' ) {
return $post_id;
}
// Create a new post
$post = array(
'post_type' => 'post', // Your post type ( post, page, custom post type )
'post_status' => 'publish', // (publish, draft, private, etc.)
'post_title' => wp_strip_all_tags($_POST['acf']['field_xxxxxxxxxxxx']), // Post Title ACF field key
);
// insert the post
$post_id = wp_insert_post( $post );
// Save the fields to the post
do_action( 'acf/save_post' , $post_id );
return $post_id;
}