Home › Forums › Backend Issues (wp-admin) › Redirect from pre_save_post › Reply To: Redirect from pre_save_post
Sure,
I call this in my custom plugin..
/* acf post generate */
function create_acf_post( $post_id )
{
// check if this is to be a new post
if( $post_id != 'new' )
{
return $post_id;
}
// Create a new post
$mytitle = get_user_meta( get_current_user_id(), 'nickname', true ) . ' - ' . $_POST['fields']['field_547959d79b64c'];
$post = array(
'post_status' => 'draft' ,
'post_title' => $mytitle,
'post_type' => 'ifcc'
);
// insert the post
$post_id = wp_insert_post( $post );
// update $_POST['return']
$_POST['return'] = add_query_arg( array('post_id' => $post_id), $_POST['return'] );
$user_id = get_current_user_id();
update_user_meta( $user_id, 'done_free', '1' );
// wp_redirect('/');
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'create_acf_post' );
and that is fired on frontend while after couple of pars are meet,, frontend, is single, is custom post (ifcc) and logged in..
// =============================
// frontend single ifcc logic
// =============================
function cpt_front($query) {
if ( !is_admin() && $query->is_main_query() ) {
if ($query->is_single() && $query->post_type == 'ifcc' ) {
if( is_user_logged_in() ){
$user_id = get_current_user_id();
$usernick = get_user_meta( $user_id, 'nickname', true );
update_field('submitee_name', $usernick);
$free = get_user_meta( $user_id, 'done_free', true );
if( $free == '1' ){
echo 'need to buy additional licence';
} else {
get_template_part( 'content', get_post_format() );
$args = array(
'post_id' => 'new',
'field_groups' => array( 68 )
);
acf_form( $args );
}
} else {
// echo get_permalink( get_option('woocommerce_myaccount_page_id') );
echo do_shortcode('[woocommerce_my_account]');
}
}
}
}
add_action('pre_get_posts','cpt_front');
so, everything works cool, and post is inserted in backend and all, but redirect part if off somehow,,
thanks
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.