Hi,
I have created a field group and am running the following code to display it:
functions.php
function my_pre_save_post( $post_id ) {
// check if this is to be a new post
if( $post_id != 'new' )
{
return $post_id;
}
// Create a new post
$post = array(
'post_status' => 'pending',
'post_title' => 'title',
'post_type' => 'events',
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
page.php
...
acf_form_head();
get_header();
...
acf_form(array(
'post_id' => 'new',
'field_groups' => array( 1450 ),
'submit_value' => 'Submit'
));
...
What happens is the form goes through as intended, but in the process the page gets redirected to a white screen with a zero on it. What do you suppose could be the problem
I am with this same problem
Hi,
As of later versions of ACF you do not need to use that filter in order for a new post to be created.
Instead you use the new_post
parameter of acf_form.
See the section under “Create a new post” here: http://www.advancedcustomfields.com/resources/acf_form/