admin管理员组文章数量:1312736
I want to check if user time zone is perth and its belong from Group A.
MY QUERY IS NOT WORKING
SELECT * FROM `wp_users` AS t1 LEFT JOIN wp_usermeta AS t2 ON
t1.ID=t2.user_id
WHERE t2.meta_key='Time_Zone'
AND t2.meta_value = 'PERTH'
AND t2.meta_key='user_class_group'
AND t2.meta_value='Group A'
THIS QUERY IS WORKING IF I USED ON 01 AND
SELECT * FROM `wp_users` AS t1 LEFT JOIN wp_usermeta AS t2 ON
t1.ID=t2.user_id
WHERE (t2.meta_key='Time_Zone')
AND t2.meta_value='PERTH'
TABLE WHICH I NEED TO CHECK
I want to check if user time zone is perth and its belong from Group A.
MY QUERY IS NOT WORKING
SELECT * FROM `wp_users` AS t1 LEFT JOIN wp_usermeta AS t2 ON
t1.ID=t2.user_id
WHERE t2.meta_key='Time_Zone'
AND t2.meta_value = 'PERTH'
AND t2.meta_key='user_class_group'
AND t2.meta_value='Group A'
THIS QUERY IS WORKING IF I USED ON 01 AND
SELECT * FROM `wp_users` AS t1 LEFT JOIN wp_usermeta AS t2 ON
t1.ID=t2.user_id
WHERE (t2.meta_key='Time_Zone')
AND t2.meta_value='PERTH'
TABLE WHICH I NEED TO CHECK
Share Improve this question edited Jan 3, 2021 at 13:28 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Jan 3, 2021 at 13:25 MukhyyarMukhyyar 1 5 |1 Answer
Reset to default 0 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;
}
Achieve the desired result through WP_User_Query
class thanks @Tony Djukic and @ Tom J Nowell
本文标签: databaseJoin Query on WPUSERMETA Table
版权声明:本文标题:database - Join Query on WP_USERMETA Table 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741867537a2401999.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
WP_User_Query
instead? It's also possible to have taxonomies for users – Tom J Nowell ♦ Commented Jan 3, 2021 at 13:52