Support

Account

Home Forums Front-end Issues ACF redirect after the publication of a new page

Solved

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.

  • Sumptuously! I am very grateful to you!

  • 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.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘ACF redirect after the publication of a new page’ is closed to new replies.