I am using the following function in themes/function.php to redirect the user to posts page after login.
/* redirect users to posts page after login */
function redirect_to_post_page() {
global $redirect_to;
if (!isset($_GET['redirect_to'])) {
$redirect_to = "http://www.site.com/wp-admin/edit.php";
}
}
add_action('login_form', 'redirect_to_post_page');
However, I want to redirect the users to My posts page in admin panel. For that I need author ID. How can I accomplish this ?
s_ha_dum (was apljdi)
Member
Posted 2 years ago #
The login_form hook isn't going to work. That runs in the login form before the user logs in, so there is no ID to be had.
Try the wp_login hook and put
print_r(get_defined_vars());
// exit; // you might need to exit to see the output
inside that function and see what you have to work with. If the ID isn't in there then you'll have to get it with something like get_currentuserinfo
I get
Array ( [redirect_to] => http://www.siteurl.com/wp-admin/ )
Even get_currentuserinfo doesn't seem to gimme the ID.
s_ha_dum (was apljdi)
Member
Posted 2 years ago #
OK, so do this:
/* redirect users to posts page after login */
function redirect_to_post_page($user) {
$user = get_userdatabylogin($user);
print_r(get_defined_vars());
}
add_action('wp_login', 'redirect_to_post_page');
Now $user has all the information you need.