Admin Post Update Redirection to Posts Screen

Is there a hook I can use that when a post is created or updated it goes back to the list/table page of all the posts. If it is also possible to target a post type as well that would be cracking.

It’s a really silly request I know and have argued the toss about it but wanted to make sure it was achievable if not very user friendly.

Read More

Steve

Related posts

1 comment

  1. Use the redirect_post_location filter and admin_url() function.

    add_filter( 'redirect_post_location', 'wpse_124132_redirect_post_location' );
    /**
     * Redirect to the edit.php on post save or publish.
     */
    function wpse_124132_redirect_post_location( $location ) {
    
        if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) )
            return admin_url( "edit.php" );
    
        return $location;
    }
    

    To redirect to a different url, add everything after the /wp-admin/ portion of the url. I used "edit.php" because the intended url was: http://example.com/wordpress/wp-admin/edit.php.


    The redirect_post_location filter is not documented in the Codex Filter Reference. You can find it in the wp-adminpost.php file near line 73. This is the WordPress code in the trunk version of WordPress:

    wp_redirect( apply_filters( 'redirect_post_location', $location, $post_id ) );
    

    As you can see, you can also test the $post_id redirect based on the $post_id or any information obtained from it. To use this second parameter of the filter, you need to pass the priority and _accepted_args_ parameters in the filter call:

    add_filter( 'redirect_post_location', 'wpse_124132_redirect_post_location', 10, 2 );
    

    And update the function parameters:

    /**
     * Redirect to the edit.php on post save or publish.
     */
    function wpse_124132_redirect_post_location( $location, $post_id ) {
    
        if ( isset( $_POST['save'] ) || isset( $_POST['publish'] ) ) {
            // Maybe test $post_id to find some criteria.
            return admin_url( "edit.php" );
        }
    
        return $location;
    }
    

Comments are closed.