Method #1: The pre_user_query
hook:
There are not many filters available, but you can try the pre_user_query
hook:
// Add filter:
add_action( 'pre_user_query', 'wpse_filter_by_reg_date' );
// Query:
$query = new WP_User_Query( $args );
// Remove filter:
remove_action( 'pre_user_query', 'wpse_filter_by_reg_date' );
where the filter callback is:
/**
* Filter WP_User_Query by user_registered date
*
* @see http://wordpress.stackexchange.com/a/160826/26350
* @param WP_User_Query The current WP_User_Query instance
*/
function wpse_filter_by_reg_date( $q )
{
global $wpdb;
$q->query_where .= $wpdb->prepare(
" AND {$wpdb->users}.user_registered >= '%s' ",
date( "Y-m-d" )
);
}
You can then modify the filter callback to your needs.
Method #2: WP_User_Query
with custom query variables:
You can also make this more dynamic, by using the custom string parameters _registered
and _registered_compare
. Then your query could be:
$args = array(
'orderby' => 'login',
'order' => 'ASC',
'_registered' => date( 'Y-m-d' ),
'_registered_compare' => '>=',
);
$query = new WP_User_Query( $args );
where:
/**
* Add support for the custom '_registered' and '_registered_compare'
* string input parameters in WP_User_Query().
*
* @see http://wordpress.stackexchange.com/a/160826/26350
* @param WP_User_Query The current WP_User_Query instance
*/
function wpse_registered_filter( $q )
{
if( isset( $q->query_vars['_registered'] )
&& isset( $q->query_vars['_registered_compare'] )
&& is_string( $q->query_vars['_registered_compare'] )
)
{
// Input:
$registered = $q->query_vars['_registered'];
$compare = $q->query_vars['_registered_compare'];
// Init:
$available_compares = array( '=', '<', '>', '<=', '>=', '!=' );
// Default compare:
if( ! in_array( $compare, $available_compares, TRUE ) )
$compare = '=';
// Modify query:
global $wpdb;
$q->query_where .= $wpdb->prepare(
" AND {$wpdb->users}.user_registered {$compare} '%s' ",
$registered
);
}
}
add_action( 'pre_user_query', 'wpse_registered_filter' );
Method #3: Manual SQL:
Responding to the comment below, this is an example how you can write the SQL manually:
global $wpdb;
$sql = $wpdb->prepare(
"SELECT ID FROM {$wpdb->users} WHERE {$wpdb->users}.user_registered >= '%s' ",
current_time( 'mysql' )
);
$uids = $wpdb->get_col( $sql );