1

I am trying to display user_nicename and one of usermeta values where meta_key is description. My query is given below:

<?php
$querystr = "
        SELECT * 
        FROM $wpdb->users, $wpdb->usermeta
        WHERE $wpdb->users.ID = $wpdb->usermeta.user_id 
        AND $wpdb->usrmeta.meta_key = 'description' 
     ";

$retrieve_data = $wpdb->get_results($querystr, OBJECT);

?>

<?php global $retrieved_data; foreach ($retrieve_data as $retrieved_data){ ?>
<table>
    <tr>
        <th>Customer Name</th>
        <th>Customer Details</th>
    </tr>
    <tr>
        <td><?php echo $retrieved_data->user_nicename;?></td>
        <td><?php echo $retrieved_data->meta_value;?></td>
    </tr>
</table>
<?php } ?>

My final output should be displayed inside a table which will look something like below: enter image description here

But I am in confusion how to do that. I am facing problem for both sql syntax and displaying data inside the table. Sorry for this easy question, I am still a learner. Can anyone help me in here? Thanks

0

To do that with WordPress functions, you can try that

$users = get_users();


?>

    <table>

        <tr>
            <th>Customer Name</th>
            <th>Customer Details</th>
        </tr>

        <?php foreach ($users as $u) {?>

            <tr>
                <td>
                    <?php echo htmlspecialchars($u->display_name);?>
                </td>
                <td>
                    <?php echo htmlspecialchars($u->description); // retrieve the meta "description"?>
                </td>
            </tr>

        <?php }?>

    </table>

<?php

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.