Home › Forums › Front-end Issues › Edit Post Form sets comment_status OFF
HI All, Ive made a front end form that allows users to save a new post. It saves with the comment_status = ture, meaning users can leave comments on the new post.
However if the post is edited using the front end form the comment_status turns off.
NEW POST: (WORKS FINE, comment_status default is ON)
$new_post = array(
'post_id' => 'new', // Create a new post
'field_groups' => $field_groups, // 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 );
EDIT/UPDATE POST: (Why does comment_status get turned OFF???)
$edit_post = array(
'post_id' => $pid, // Edit post
'field_groups' => array(8832), // Create post field group ID(s)
'form' => true,
'return' => '%post_url%', // Redirect to new post url
'html_before_fields' => '',
'html_after_fields' => '',
'submit_value' => 'Update Post',
'updated_message' => 'Saved!'
);
acf_form( $edit_post );
Please help! 🙂 Thanks
Hi @adeon
I believe you’re using ACF free version. That means that you need to use extra functions to save the post. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/?version=4.
I’m not really sure why it changes the comment status, bu you can always use the acf/save_post
hook to change it back like this:
function my_acf_save_post( $post_id ) {
// Only do it for the front end form
if( is_admin() ){
return;
}
// set the comment status
$my_post = array(
'ID' => $post_id,
'comment_status' => 'open',
);
// remove action to avoid infinite loop issue
remove_action('acf/save_post', 'my_acf_save_post', 20);
// update the post
wp_update_post( $my_post );
// add the action back
add_action('acf/save_post', 'my_acf_save_post', 20);
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
I hope this helps 🙂
HI James,
Thanks heaps for the feedback.. Im Using ACF FORMS PRO. Ill give the above a try and let you know how I go.
Regards
Adeon
Hi @adeon
In that case, you need to set the ‘post_id’ option to ‘new_post’ instead of ‘new’ like this:
'post_id' => 'new_post',
Thanks 🙂
The topic ‘Edit Post Form sets comment_status OFF’ 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.