How can I call a row of user specific data from a custom table added to the WP Database

Aftere long hours of research through the WordPress Codex and a variety of Forum Posts and tutorials. Here is the solution for my current issue.

First I began by calling the current logged in user.

<?php global $current_user;
wp_get_current_user();    ?>

From there I connected to the database. Seeing as I added the table within the WordPress database I used the global statement and selected the database table and information I wanted to as well as prepared it for query.

<?php global $wpdb;
$userid = $current_user->user_login;
$result = $wpdb->get_results( "SELECT * FROM custom_table WHERE CARD = $userid");
// $query = "SELECT * FROM custom_table WHERE CARD = $userid";
// $result = $wpdb->get_results($query);

?>
<?php foreach ( $result as $query )   {?>

Then to call the individual fields/column data for the specific user I simply echoed the various queries of the custom_table’s columns which I wanted to populate on my web page.

<?php echo $query->ColumnName; ?>

I hope some of the community find this helpful. And my edits to this Answer are more detailed for those who come across this post in the future.

Leave a Comment