0

When editors go to edit.php

http://www.website.com/wp-admin/edit.php

I would like to automatically pass extra variables as

http://www.website.com/wp-admin/edit.php?orderby=123&order=desc

There is a solution with wp_redirect but it will create infinite loop.

Thanks for your help.

jjj
  • 925
  • 8
  • 22

1 Answers1

1

You can do this with admin_menu action, The following code should work :

add_action( 'admin_menu', function(){
    global $menu, $submenu;

    foreach( $submenu['edit.php'] as $k => $v ){
        if( $v['2'] == 'edit.php' ) {
            $submenu['edit.php'][$k]['2'] = 'edit.php?orderby=123&order=desc';
            break;
        }
    }
}, 99 );
Amin
  • 1,234
  • 1
  • 14
  • 35
  • @jjj I just tested the code and it's working, make sure you're adding it to `functions.php`, also try using `999` instead of `99` and make sure you're using php 5.3+, because [anonymouse functions](https://stackoverflow.com/questions/9148841/which-version-of-php-added-anonymous-functions) won't work in versions earlier than 5.3.0 – Amin Jan 24 '18 at 22:10
  • Sorry i think i mis-understood you, do you mean `wp-admin/edit.php` or `edit.php` as an endpoint to root domain? – Amin Jan 24 '18 at 22:15