I am trying to retrieve a list of sites within my WordPress multisite instance that were registered before a given date/time.
Working with get_sites()
and WP_Date_Query
I have the following, but no sites are being returned...
$now = current_time( 'timestamp' );
$lifetime = epd_get_default_site_lifetime(); // returning 3600. Aim to retrieve all sites registered over an hour ago
if ( ! $lifetime ) {
return;
}
$delete_on = $now - $lifetime;
$delete_sites_query = array(
'site__not_in' => array( get_network()->blog_id ),
'date_query' => array(
array(
'year' => date( 'Y', $delete_on ),
'month' => date( 'n', $delete_on ),
'day' => date( 'j', $delete_on ),
'hour' => date( 'G', $delete_on ),
'minute' => intval( date( 'i', $delete_on ) ),
'second' => intval( date( 's', $delete_on ) ),
'compare' => '<=',
'column' => 'registered'
)
)
);
$delete_sites_query = apply_filters( 'epd_delete_sites_query', $delete_sites_query );
$sites = get_sites( $delete_sites_query );
If I var_export( $delete_sites_query );
I see the following (which appears to be correct to me)...
array (
'site__not_in' =>
array (
0 => '1',
),
'date_query' =>
array (
0 =>
array (
'year' => '2018',
'month' => '8',
'day' => '14',
'hour' => '22',
'minute' => 46,
'second' => 19,
'compare' => '<=',
'column' => 'registered',
),
),
)
I have sites registered prior to the date above...