2

I am looking to display different content after a user registers. Is there a way to find out the registration date and then if it's been 1 day display one thing, but if it's been 2 days display something else?

Something like this, but based on the registration date and not a post entry date:

<?php if (strtotime($post->post_date) > strtotime('-30 days')): ?>
   //Text for posts created in the last 30 days
<?php endif; ?>
6

Yes you can!

<?php 
get_currentuserinfo(); 
$user_data = get_userdata($user_ID);
$registered_date = $user_data->user_registered;
if (strtotime($registered_date) > strtotime('-30 days')){
   //Text for users registered in the last 30 days
}
?>

hope this helps

  • Thanks for the help but I am getting this error now: Fatal error: Cannot use object of type stdClass as array – Red Jan 31 '11 at 17:44
  • my bad, i updated the code, its $user_data->user_registered instead of $user_data['user_registered'], if not then paste your code here so we could see – Bainternet Jan 31 '11 at 17:59
  • Thanks for the quick response. I have simply pasted this code into a wordpress template, so no additional code to share and I am now getting this error:Parse error: syntax error, unexpected – Red Jan 31 '11 at 18:09
  • ok weird, try the posted answer now and id not please post your code – Bainternet Jan 31 '11 at 18:22
  • Ok, figured it out. I edited the code above. It was missing a ending ) after $registered_date – Red Jan 31 '11 at 18:32
0

The above code is now deprecated.

    <?php  
$user_data = get_userdata(get_current_user_id());
$registered_date = $user_data->user_registered;
if (strtotime($registered_date) > strtotime('-30 days')){
   //Text for users registered in the last 30 days
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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