Few months ago, I updated the Codex for get_users()
and WP_User_Query
, regarding the date_query
support on the user’s registration date, in WordPress 4.1+.
Then I also added a simple example on how to find users that registered during the last 12 hours.
But the current question is how to find users that registered today.
We could simply use relative date string:
$args = [
'date_query' => [
[ 'after' => 'today', 'inclusive' => true ],
]
];
$query = new WP_User_Query( $args );
that will generate the following SQL query:
SELECT SQL_CALC_FOUND_ROWS wp_users.* FROM wp_users WHERE 1=1 AND (
wp_users.user_registered >= '2015-11-06 00:00:00'
) ORDER BY user_login ASC ;
We might also set the year
, month
and day
parameters explicitly:
$args = [
'date_query' => [
[
'year' => current_time( 'Y' ),
'month' => current_time( 'm' ),
'day' => current_time( 'd' ),
],
]
];
$query = new WP_User_Query( $args );
that will generate:
SELECT SQL_CALC_FOUND_ROWS wp_users.* FROM wp_users WHERE 1=1 AND (
(
YEAR( wp_users.user_registered ) = 2015
AND MONTH( wp_users.user_registered ) = 11
AND DAYOFMONTH( wp_users.user_registered ) = 6
)
) ORDER BY user_login ASC ;
Informative article, totally what I needed.