• shamratdewan

    (@shamratdewan)


    Hi, I have ninja forms post on a frontend with a edit button, when clicked it takes the user to admin area, once the data is updated, wordpress bring the user back to the edit action page But i want them to go to my custom page.

    i have used “save_post” hook which works fine but the new form submission does not work. may be because its firing on new form save action as well.

    so i tried edit_post hook which redirect the page but it does not perform the post data update, it simple redirects to the page i want to go without any update on the edit form of wp backend.

    what hook i can use so that it will only trigger when the post is updated and then it will redirect to a new page

    function my_project_updated( $post_id ) {
     
        // If this is just a revision, don't send the email.
        $urlto = "https://wpengine.com/post-list/";
    		wp_redirect( $urlto );
    		exit;
     
    }
    add_action( 'edit_post', 'my_project_updated' );

    above code redirect but does not update the post content.
    I want this hook to fire only when the user is updating an old post and it should not trigger when the user create a new post.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Redirecting out of an action hook is generally not recommended. WP expects to regain control after doing actions. In many if not most cases, WP is not finished doing what it is supposed to do when it does actions. There are instances where filter hooks are specifically used for redirection. In these cases, the destination is filtered and the actual redirection is done by WP, so you still do not redirect out of a callback.

    I suggest asking in Ninja Forms’ dedicated support channel what the proper way is to redirect to another page after a form submission. I strongly suspect they have a specific method in mind. I’ve not used Ninja Forms, but in other similar plugins this takes the form a a JavaScript redirect when a certain event fires.

    OTOH, if I were coding my own form without the help of a forms plugin, I would simply have my custom page template deal with the form submittal.

Viewing 1 replies (of 1 total)
  • The topic ‘Hook not working as wanted’ is closed to new replies.