4

How could I change the redirect location after a user trashes a page? Right now they go to all pages here:....wp-admin/edit.php?post_type=page

I want them to go here:......wp-admin/edit.php?post_type=page&page=custom_page_order

1 Answer 1

5

Hook into load-{screen_id} and check if the $_GET['trashed'] variable is 1 or above.

add_action('load-edit.php','wpse_trashed_redirect');
function wpse_trashed_redirect(){
    $screen = get_current_screen();
    if('edit-page' == $screen->id){
        if( isset($_GET['trashed']) &&  intval($_GET['trashed']) >0){
            $redirect = add_query_arg(array('page'=>'custom_page_oder', 'trashed' => false, 'ids' => false ));
            wp_redirect($redirect);
            exit();
        }
    }
}

This works - and I'm not aware of a better way of doing this...

4
  • I think this is close. I get this url:/wp-admin/edit.php?post_type=page&trashed=1&ids=112&page=custom_page_oder It needs to be: wp-admin/edit.php?post_type=page&page=custom_page_order
    – Shae
    Commented May 22, 2012 at 20:08
  • I can't get it to remove the trash id from the URL? Any ideas?
    – Shae
    Commented May 24, 2012 at 12:24
  • I just edited the answer to make it remove ids and trash variable from the redirected url
    – Shazzad
    Commented Dec 11, 2013 at 16:32
  • If not obvious, if('edit-page' == $screen->id).. would change to if('edit-book' == $screen->id) if 'book' is your custom post type
    – JJ Rohrer
    Commented Apr 30, 2019 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.