Notifications
Clear all

[Solved] How to get the ID of the WordPress user...

3 Posts
2 Users
2 Likes
708 Views
Andrew Mackinnon
Posts: 12
Topic starter
(@hereamack)
Eminent Member
Joined: 2 years ago

Hi

I'm having a lot of trouble with the PHP script below that I need to run on a .php page of my WordPress website which hosts a set of wpForo forums.

I need to obtain the field wa_wpforo_profiles.userid or the field wa_users.ID relating to the user who is logged in to the WordPress website when this script runs as a .php page of my WordPress website.

I have tried using $user_id = get_current_user_id(); and it didn't work.

If there is anything that anybody can please do to help, I would really appreciate it.

I really am at a loss.  I don't know how to solve this problem at all but I have put at least four hours into it already.

Thanks a lot for any assistance you can provide.

 

Sincerely

Andrew Mackinnon

 

<?php

$servername = "redacted";
$username = "redacted";
$password = "redacted";
$dbname = "redacted";

$user_id = ???;

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
//if ($conn->connect_error) {
// die("Connection failed: " . $conn->connect_error);
//}

$sql = "UPDATE wa_wpforo_profiles SET groupid = 6, title = 'Subscriber' WHERE userid = $user_id";

$conn->query($sql);

$conn->close();

?>

2 Replies
Chris
Posts: 3650
(@chris)
Famed Member
Joined: 3 years ago

Hi @hereamack,

This is free support and we don't provide support for such custom codes.

If you need a function for your forum, you can contact Gvectors Custom Work Team for that, contact email: sales[at]gvectors.com

Andrew Mackinnon
Posts: 12
Topic starter
(@hereamack)
Eminent Member
Joined: 2 years ago

@Chris

Thanks a lot for letting me know.  I appreciate it!