简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM