Home › Forums › General Issues › pre_save_post using \'import_id\' › Reply To: pre_save_post using \'import_id\'
This is the code that works for me. Note the $GLOBALS['acf_form']['return']
function my_pre_save_post( $post_id )
{
// check if this is to be a new post
if( $post_id != 'new' ) {
return $post_id;
};
$title = trim($_POST['acf']['field_5702e3df3ce82']);
// Create a new post
$post = array(
'post_status' => 'publish' ,
'import_id' => $_POST['acf']['field_5702b6a15e788'],
'post_title' => $title,
'post_name' => sanitize_title( $title ),
'post_type' => 'app'
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $GLOBALS['acf_form']['return'] );
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post');
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.