Search code examples
wordpresshttp-redirectbackendposts

Redirect from edit.php to different page in wordpress backend


Trying to setup a redirect for Wordpress backend. I have used this code:

function redirected_admin_pages(){
    global $pagenow;

    if($pagenow == 'edit.php'){
       wp_redirect('edit.php?post_status=publish&post_type=post');
       exit;
    }
}
add_action('admin_init', array($this, 'redirected_admin_pages'));

I based it on the answer here https://wordpress.stackexchange.com/questions/52114/admin-page-redirect

For some reason I cant get it work. What am I doing wrong?


Solution

  • Well I got there in the end with a login redirect, see function below:

    add_action( 'admin_menu', 'name_changing_thing' );
    
    function name_changing_thing() {
      global $submenu;
    
      foreach( $submenu['edit.php'] as $key => $value )
      {
        if( in_array( 'edit.php', $value ) )
        {
            $submenu['edit.php'][ $key ][2] = 'edit.php?post_status=publish&post_type=post';
        }
      }
      }
    

    Thank you to anyone who looked.