Usermeta data unserialize, extract and display in table in WordPress

Question

I would like to know how to extract data from WordPress, unserialize and show it in a table.
Below is my starting point. The columns address, group and divider all have serialize data in.

I have read about get_user_meta() but not sure how to use it.

Any suggestion welcome.

[insert_php]
    //connection details
     require_once('/home/xxx/private/xxx.php');
     
        $query = "SELECT MAX(CASE WHEN wp_usermeta.meta_key = 'first_name' then wp_usermeta.meta_value ELSE NULL END) as first_name, 
                        MAX(CASE WHEN wp_usermeta.meta_key = 'last_name' then wp_usermeta.meta_value ELSE NULL END) as last_name,
                        MAX(CASE WHEN wp_usermeta.meta_key = 'pm_field_13' then wp_usermeta.meta_value ELSE NULL END) as address,
                        MAX(CASE WHEN wp_usermeta.meta_key = 'pm_field_101' then wp_usermeta.meta_value ELSE NULL END) as group,
                        MAX(CASE WHEN wp_usermeta.meta_key = 'pm_field_105' then wp_usermeta.meta_value ELSE NULL END) as divider,
                        wp_users.user_login            
                        FROM wp_users
                        LEFT JOIN wp_usermeta
                        ON wp_users.ID = wp_usermeta.user_id
                        GROUP BY wp_users.user_login"; 
       $filter_Result = mysqli_query($connect, $query) or die("Error: ".mysqli_error($connect));
       return $filter_Result;
       $num_rows = mysqli_num_rows($search_result);
    
               <table id="indextable" style="table-layout: fixed; width: 100%;" >
                    <thead>
                    <tr>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Address</th>
                        <th>Group</th>
                        <th>Divider</th> 
                     </thead>
                    </tr>
    
          <!-- populate table from mysql database -->
                    <?php while($row = mysqli_fetch_array($search_result)):?>
                    <tr>
                        <td><?php echo $row['first_name'];?> </td>
                        <td><?php echo $row['last_name'];?></td>
                        <td><?php echo unserialize($row['address']); ?></td>
                        <td><?php echo unserialize($row['group']);?></td>
                        <td><?php echo unserialize($row['divider']);?></td>             
                    </tr>
    
                    <?php endwhile;?>
                </table>
    
    [/insert_php]
0
Ryks 4 months 0 Answers 13 views 0

Leave an answer