0

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'

enter image description here TABLE WHICH I NEED TO CHECK

5
  • 1
    Have you tried using WP_User_Query instead? It's also possible to have taxonomies for users – Tom J Nowell Jan 3 at 13:52
  • no actually I've almost finish this through query just stuck on one step on query. can you please help me out to get achieve result through query – Mukhyyar Jan 3 at 13:58
  • I'm sorry I cannot, but there's a very easy way to get this data in PHP code, you do not need to make a raw SQL query – Tom J Nowell Jan 3 at 14:15
  • can you guide me with WP_user_query? – Mukhyyar Jan 3 at 14:25
  • You can start here: developer.wordpress.org/reference/classes/wp_user_query Try writing the query and then edit your question and someone can help you through the finer points. – Tony Djukic Jan 3 at 18:14
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.