I've been successful in doing most of what I want to do. I'm creating profile pages on an association website where staff will be able to see all of a members information on nicely formatted profile pages. I'm using the get_query_var function to query the page (http://yoursite.com/profile/?profile=1783 for example).
On the profile pages themselves I load this code first:
<?php $vars = get_query_var( 'profile' ); ?>
And then below I run the queries. Such as:
<?php $user_info = get_userdata((int) $vars); echo $user_info->last_activity . "
"; ?>
(The (int) $vars
grabs the user ID from the url.)
This is working great for user meta data, but when I try to grab data using $wpdb from other tables I'm having some trouble. For example, I'm trying to grab data from a MemberPress table on transactions. It returns data but not for the right user. For some reason it always returns values for user 756.
Here's the code I'm using.
<?php $status = $wpdb->get_var("SELECT status FROM wp_acfzia_mepr_transactions WHERE user_id = '(int) $vars);' "); echo $status; ?>
It's clearly working but not getting the "user_id" value correct. It always returns user 756. Pretty bizarre. Any help is appreciated. Thanks.