WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

Your Answer


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.