Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to use meta_query to return all users that have registered today :

$args = array(
    'meta_query' => array(
            'key' => 'user_registered',
            'value' => date('Y-m-d'),
            'compare' => '=',
            'type' => 'DATE'

$query = new WP_User_Query( $args );
$users = $query->get_results();

This doesn't seem to work though. What am I missing ?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The field user_registered is not a in the *_usermeta table, but the in *_users.

Nor do there seem to be any appropriate hooks to alter the SQL statement when using WP_User_Query. It seems you will need to use a direct SQL statement.

Another (minor) complication is that the registered date is stored as a date-time.

function wpse51485_get_users_registered_on( $date='' ){
    global $wpdb;

    if( empty($date) )
        $date = date('Y-m-d');

    $morning = new DateTime($date. ' 00:00:00');
    $night = new DateTime($date.' 23:59:59'); 
    $m = $morning->format('Y-m-d H:i:s');
    $n = $night->format('Y-m-d H:i:s');

    $sql = $wpdb->prepare("SELECT wp_users.* FROM wp_users WHERE 1=1 AND CAST(user_registered AS DATE) BETWEEN %s AND %s ORDER BY user_login ASC",$m,$n);

    $users = $wpdb->get_results($sql);

    return $users;
share|improve this answer
Thanks Stephen, that worked! –  mike23 May 8 '12 at 11:04

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.