Home › Forums › Front-end Issues › Pre-populated fields problem
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;
}
I had this issue. I ended up clearning _new_ fields from wp_options table and that also worked.
I had to delete all the “new_” fields from wp_options but they keep getting generated (for select fields). Do you know what is causing this ?
The topic ‘Pre-populated fields problem’ is closed to new replies.
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.