I found this code and corrected it a bit. But it does not work properly. I want to count new users (daily and monthly) who join the site. For example :
new users today: 5 new users month: 30
Can anyone modify and test my code?
$date = getdate();
$data_user_reg = $wpdb->get_results("SELECT COUNT(*) FROM $wpdb->users WHERE user_registered AND MONTH(user_registered)= $date[mday]");
CodePudding user response:
getdate();
return
Array
(
[seconds] => 31
[minutes] => 6
[hours] => 6
[mday] => 3
[wday] => 5
[mon] => 6
[year] => 2022
[yday] => 153
[weekday] => Friday
[month] => June
[0] => 1654236391
)
and you use
mday
means day of month
for day base count query is
$date = getdate();
$data_user_reg = $wpdb->get_results("SELECT COUNT(*) FROM $wpdb->users WHERE user_registered AND DAY(user_registered)= $date[mday]");
for month base count use
mon
and query is
$data_user_reg = $wpdb->get_results("SELECT COUNT(*) FROM $wpdb->users WHERE user_registered AND MONTH(user_registered)= $date[mon]");
CodePudding user response:
Thankyou. but not worked. new my co
$date = getdate();
$data_user_reg = $wpdb->get_results("SELECT COUNT(*) FROM $wpdb->users WHERE user_registered AND MONTH(user_registered)= $date[mon]");
$data_count = count($data_user_reg);
echo $data_count;
i created a new user, but it does not give the correct statistics. and always returns the number 1 !! Can you test my code and modify it?