I am working on the matrimonial site. I have created a login and registration form for the user. And for storing info I have created custom tables.

In my login form, there are two fields EmailID and password.

For another user I can check if a user is registered.

But using the same form how can I check the user is admin?

There is a problem in the password field.

(After successful login I want the admin to redirect to some pages likes report and all)

So the dashboard login and this login have to be separate

1 Answer 1


Why in the first place you created custom tables? There is wp_usermeta table for storing any kind of extra data to build custom user profiles with extra fields.

Also you can hook into native WP login process and allow logging in with email.

What method of logging in you are using?

Checking if user is administrator:

if ( current_user_can( 'manage_options' ) ) {
/* A user with admin privileges */
    wp_redirect( 'YOUR_TARGET_ABSOLUTE_URL' );

But there's even better way, as described in Codex:

function my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
global $user;
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    //check for admins
    if ( in_array( 'administrator', $user->roles ) ) {
        // redirect them to the default place
        return $redirect_to;
    } else {
        return home_url();
} else {
    return $redirect_to;

add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );

The function is pretty self explanatory. Change $redirect_to destination to one of your choice.

  • Above code is good for redirecting But now how shoul I check user is logged in Which information is stored in custom table
    – bhagya_kz
    Commented Sep 25, 2014 at 9:03
  • That's why I asked "Why in the first place you created custom tables?". Because if you store users (not only usermeta, but user logins and passwords) in your own custom table, you can't use native WP login functions, and the function is_user_logged_in() will not help you. But if you use native WP user table and registration/login process, with your own custom form and custom desing, on a custom page - then that is the function to use. See codex.wordpress.org/Function_Reference/is_user_logged_in Commented Sep 25, 2014 at 11:29
  • I am getting but I have huge data.And I have no option than creating custom table.
    – bhagya_kz
    Commented Sep 26, 2014 at 4:31
  • I'm working on a large wp multisite project right now with 65k already registered users and the numbers will grow to millions. We have custom registration, login, lostpassword etc (actually, all of them are just customized via actions and filters native wp features). Every user has its own 'profile' custom post type post with lots of usermeta, relationships to another post type objects and taxonomies. Everything works fine with native wp APIs because we are making proper use of all the core features wp has to offer. Commented Sep 26, 2014 at 8:16
  • The only problem with wp native usermeta table is that it has no indexes on meta values. So, quering users by custom meta values will do full table scans. But instead of creating completely custom tables we are working on an additional table with indexes, spinning up the concept of 'horizontal meta' proposed by horizontalmeta.com plugin. Commented Sep 26, 2014 at 8:20

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.