0

I make one custom registration form and add more field address, mobile Number but all subscriber make table his but how to get value address column in my table,

<?php
      global $wpdb;
      // $authors = $wpdb->get_results("SELECT * from $wpdb->usermeta WHERE meta_key = 'wp_capabilities' AND meta_value = 'a:1:{s:10:\"subscriber\";b:1;}'");

      $mysqli=NEW mysqli('localhost','root','','wp1');
      $sql = "SELECT wp_users.ID, wp_users.user_nicename, wp_users.user_email,wp_users.user_registered FROM wp_users INNER JOIN wp_usermeta 
      ON wp_users.ID = wp_usermeta.user_id 
      WHERE wp_usermeta.meta_key = 'wp_capabilities' 
      AND wp_usermeta.meta_value LIKE '%subscriber%' 
      -- AND wp_users.user_email     
      ORDER BY wp_users.user_nicename";
      $result = $mysqli->query($sql);

      // var_dump($resultl);

      // var_dump($result);
          
      echo "<table class='table table-striped table-class' id= 'table-id'>
          <thead>

          <tr>

          <th style='padding:20px;border:1px solid;color:#489ACF;width:150px; '>Email</th>
          <th style='padding:20px;border:1px solid;color:#489ACF; '>Username</th>
          <th style='padding:20px;border:1px solid;color:#489ACF; '>Date</th>
          <th style='padding:20px;border:1px solid;color:#489ACF; '>Address</th>
          <th style='padding:20px;border:1px solid;color:#489ACF; '>Mobileno</th>
          </tr>  <thead>";


     while($rows=$result->fetch_assoc()){
            // $user_email=$rows['user_email'];
            // $user_login=$rows['user_nicename'];
            // $date=$row['user_registered'];
            // $user_id=$rows['ID'];
            // echo $user_id;
            echo "  <tbody> <tr>";

    // echo "<td>" . $row['id'] . "</td>";
            echo "<td style='padding:20px;border:1px solid;color:#489ACF; '>" . $rows['user_email']. "</td>";
            echo "<td style='padding:20px;border:1px solid;color:#489ACF; '>" .$rows['user_nicename']. "</td>";
            echo "<td style='padding:20px;border:1px solid;color:#489ACF; '>" .$rows['user_registered']. "</td>";
            // echo "<td style='padding:20px;border:1px solid;color:#489ACF; '>" .$rows['address']. "</td>";
            // echo "<td style='padding:20px;border:1px solid;color:#489ACF; '>" .$rows['mobile_no']. "</td>";
        
            echo "</tr>  <tbody>";

          }
          echo "</table>";

           
?>

how to get value and make table .... inner join it work full but how

armagedescu
  • 1,758
  • 2
  • 20
  • 31
bca tech
  • 26
  • 1
  • 8

1 Answers1

1

Since you are using wordpress, it makes sense to use Wordpress API. This is how you find the users by specific meta attributes:

   $users = get_users(array(
            'meta_key'     => 'wp_capabilities',
            'meta_value'   => 'subscriber',
             ...any other keys => values...
         ));

If you need to get user by role you can get users like this

$users = get_users( array(
    'role'    => 'subscriber',
    'orderby' => 'user_nicename',
    'order'   => 'ASC'
   ));
...
foreach ( $users as $user ) ...

In that way you will get an array of WP_Users. Iterate the array and extract from it any data you need.
Check for more information on wordpress documentation about function as well as WP_User object. In order to add user metadata you also have to use wordpress api provided, this is only a sample of adding meta, but not the right method to add roles:

   add_user_meta( $user_id, 'wp_capabilities', 'subscriber', false /*non unique*/ );

Suppose the above $user_id you got with a function like wp_insert_user or any other way you can get the id
To add correctly any roles use add_role function or any other role functions https://developer.wordpress.org/reference/functions/add_role/

armagedescu
  • 1,758
  • 2
  • 20
  • 31