Getting the current logged in user ID?
-
This appears to be harder than I think! I thought I had this right, but for some reason it won’t output the user ID!
Now the point of this function is to eventually declare that the user is already a part of one group, and as such can’t join any others. This is one of the main points of the site – incidentally, I’m surprised that I’ve been unable to find a plugin for this.
Here’s the code:
function one_group_only() {
global $wpdb, $bp;$sql = “SELECT *, COUNT(user_id) FROM fn_bp_groups_members
WHERE user_id = {$bp->loggedin_user->id}”;
print_r($sql);
die();
}
do_action( ‘one_group_only’ );
one_group_only();So what this function does so far is tries to output the query to the database (that’s as far as I’ve gotten). The query that was output was this:
SELECT *, COUNT(user_id) FROM fn_bp_groups_members WHERE user_id =
And that’s it, I have no idea why it can’t recognise the user ID. It’s a little frustrating, as I think I’ve gotten it right. Called the correct $bp global, used the correct reference point to find the exact string, and my SQL output doesn’t cause any problems when I manually put the test user ID in.
Any ideas?
- The topic ‘Getting the current logged in user ID?’ is closed to new replies.