Redirect to “All Posts” after post update or publish in Block Editor

As far as I can see, the function redirect_post, where the redirect_post_location filter resides, is not automatically called anywhere, so that filter won’t be triggered. The save_post hook (or preferably save_post_post_type) still works, but not with metaboxes, as Gutenberg saves these separately using ajax calls. Ajax calls run in the background and do not affect the current page. As a result redirects don’t work.

So, you cannot reliably redirect by calling the server. However, you can redirect on the user end by binding an extra jquery action to the save button. Something like this:

jQuery( document ).ready( function( $ ) {
    var url="your_url/edit.php?post_type=mycptslug";
    $( '.editor-post-publish-button__button' ).on( 'click',
        function() {
            window.location.href = url;
            });
        }
    );
});

Note: Didn’t test the jquery, so might be buggy, but you get the picture. Make sure this is executed after the ajax save call by loading it late.

Leave a Comment