I have two different table in wordpress one is custom table and another is wp_usermeta table.

one email is matched from both table so i want to get data from both table using email address is matched. My query is:

$sql = "SELECT * FROM wp_usermeta,tbl_information 
WHERE   wp_usermeta.meta_value = 
tbl_information.account_email AND 
((wp_usermeta.meta_key = 'mycv') OR (wp_usermeta.meta_key = 'drivinglicence') OR 
(wp_usermeta.meta_key = 'first_name') OR (wp_usermeta.meta_key = 'last_name') OR 
(wp_usermeta.meta_key = 'address') OR (wp_usermeta.meta_key = 'nickname'))"

$infos = $wpdb->get_results($sql);

foreach ($infos as $u) {
      $users[$a->user_id][$a->meta_key] = $a->meta_value;
foreach ($users as $u) {
   <?php echo $u['first_name'].' '.$u['last_name'];?>

This is works but when i try to print tbl_information table data like one of the field is: account_name

So i try to print like <?php echo $u['account_name'];?>

But it wont work.

  • did you try a var_dump on $u Jul 14, 2020 at 7:03
  • yes i got all details on their. but not print it
    – Shawn
    Jul 15, 2020 at 4:17
  • try updating the question with the result of var_dump above Jul 15, 2020 at 6:03


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.