Bob Lozano
Bob Lozano

Reputation: 592

Showing specific information of current user logged in, in PHP

I'm using this 2 plugins

http://www.wpexplorer.com/wordpress-user-contact-fields/ and WooCommerce

The 1st parameter, in this case the number "1" refers to the id of the user, how con I change it to be dynamic? So, depending on the user I get its own specific information

<h2>Personal</h2>
<?php
echo '<ul>';
echo '<li>Direccion: ' .get_user_meta(1,'address',true) . '</li>';
echo '<li>Compañia: ' .get_user_meta(1,'company',true) . '</li>';
echo '<li>Birth dAte: ' .get_user_meta(1,'birth',true) . '</li>';
echo '<li>Gender: ' .get_user_meta(1,'gender',true) . '</li>';
echo '<li>phone: ' .get_user_meta(1,'phone',true) . '</li>';
echo '</ul>';
?>

thanks

Upvotes: 0

Views: 100

Answers (1)

I wrestled a bear once.
I wrestled a bear once.

Reputation: 23379

Don't try to make a function do something it wasn't intended to do. Write your own. Especially for something this simple.

function getUserStuff($id, $item){
    $item = mysql_real_escape_string($item);
    $id = mysql_real_escape_string($id);
    $q = mysql_query("SELECT `".$item."` FROM `users` WHERE `id` = '".$id."'");
    $z = mysql_fetch_assoc($q);
    return (mysql_num_rows($q) > 0) ? $z[$item] : false;
}

This is just an example. I used a deprecated function for simplicity but you should use a different API.

Upvotes: 1

Related Questions