Last active
December 18, 2015 19:49
-
-
Save bordoni/5835456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$role = 'subscriber'; | |
if ( false === ( $userids = get_transient( "monthly_userids.{$role}" ) ) ) { // If the transient isn't set do it! | |
global $wpdb; | |
$start_date = date('Y-m-d H:i:s', strtotime('first day of this month')); | |
$end_date = date('Y-m-d H:i:s', strtotime('first day of next month')); | |
$userids = $wpdb->get_col( $wpdb->prepare( "SELECT SQL_CALC_FOUND_ROWS `user`.`ID` as `ID` FROM `{$wpdb->users}` AS `user`, `{$wpdb->usermeta}` AS `meta` WHERE 1=1 AND (`meta`.`user_id` = `user`.`ID` AND `meta`.`meta_key` = 'em_capabilities' AND `meta`.`meta_value` LIKE '%s') AND `user`.`user_registered` BETWEEN '%s' AND '%s' GROUP BY `user`.`ID`;", "%{$role}%", $start_date, $end_date ) ); | |
set_transient( "monthly_userids.{$role}", $userids, 60*60*12 ); | |
} | |
// Ready to use "$userids" as an array of the available users. | |
// To expire the data from the "object" cache, use the code below | |
$role = 'subscriber'; | |
delete_transient("monthly_userids.{$role}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment