Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'd like to determine how many times a user has logged in. Does WordPress retain that information or will I have to add a db entry every time they log-in?

if(is_user_logged_in() && ($logged_in_times == 2)) {
    // do something
}
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I don't think so. You will need to do something like this (untested):

add_action("wp_login", "my_login_function");

function my_login_function($username){
   $userdata = get_user_by('login', $username);
   $n = get_user_meta($userdata->ID, "my_login_counter", true);
   if (! is_numeric($n)) $n = 0;
   $n = intval($n) + 1;
   update_user_meta($userdata->ID, "my_login_counter", $n);
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.