3

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?

Community
  • 1
  • 1
user1721230
  • 317
  • 1
  • 6
  • 19
  • If I change to `add_action('admin_init', 'redirected_admin_pages');` I get a redirect loop, so its doing something! how can I redirect without the loop? – user1721230 Sep 01 '14 at 21:23
  • I just Realised I should have posted this on the Wordpress site. Is it too late to delete this post and put it there instead. Sorry – user1721230 Sep 01 '14 at 21:31

1 Answers1

3

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.

user1721230
  • 317
  • 1
  • 6
  • 19