function get_users_email ($time_zone_cont, $class_group){
// Add Lisa\'s user id, 14, in an array.
$exclude_list = array( );
$Time_Zone = $time_zone_cont;
$user_class_group = $class_group;
$args = array(
// \'role\' => \'Editor\',
// \'exclude\' => $exclude_list,
\'meta_query\' => array(
// \'relation\' => \'OR\',
array(
\'key\' => \'Time_Zone\',
\'value\' => $Time_Zone,
\'compare\' => \'=\'
),
array(
\'key\' => \'user_class_group\',
\'value\' => $user_class_group,
\'compare\' => \'=\'
)
)
);
// Custom query.
$my_user_query = new WP_User_Query( $args );
// Get query results.
$results = $my_user_query->get_results();
// Check for editors
if ( ! empty( $results ) ) {
foreach ( $results as $result ) {
// Get each editor\'s data.
$output = get_userdata( $result->ID );
// Show editor\'s name.
$get_output[] = $output->user_email;
}
}
return $get_output;
}
通过以下方式实现所需结果
WP_User_Query
感谢Tony Djukic和Tom J Nowell