Home › Forums › Front-end Issues › ACF redirect after the publication of a new page
Hello!
There are several options for redirection after the publication of the post. For example, the post page:
'return' => '%post_url%',
or to any page:
'return' => home_url('contact-form-thank-you'),
Is it possible to substitute the ID of a new post in the link? I want to immediately after the creation of the page to edit it using the frontend Visual Composer. I should get this link: http://mysite.com/wp-admin/post.php?vc_action=vc_inline&post_id=2&post_type=page. How to set up a redirect for this?

Hi @buylov
Maybe you can try this code?
function my_pre_save_post( $post_id ) {
// check if this is to be a new post
$GLOBALS['acf_form']['return'] = add_query_arg( array(
'vc_action' => 'vc_inline',
'post_id' => $post_id,
'post_type' => 'page',
), 'http://mysite.com/wp-admin/post.php');
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
Please take a look at this thread to learn more about it: http://support.advancedcustomfields.com/forums/topic/pass-new-post_id-to-url-or/.
Hope this helps.
I apologize for clarification. But is there a way to use this code only to certain types of posts, in particular, only the pages?

Hi @buylov
Something like this maybe?
function my_pre_save_post( $post_id ) {
if( get_post_type($post_id) == 'page' ){
$GLOBALS['acf_form']['return'] = add_query_arg( array(
'vc_action' => 'vc_inline',
'post_id' => $post_id,
'post_type' => 'page',
), 'http://mysite.com/wp-admin/post.php');
}
// return the new ID
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post', 10, 1 );
Don’t forget to set 'post_type' => 'page', in your acf_form() function.
Hope this helps.
The topic ‘ACF redirect after the publication of a new page’ 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.