I want to make custom code website function into wordpress.
its continuation from My URL question here: https://stackoverflow.com/questions/65456090/change-default-user-profile-url-bbpress-plugin
I have code that insert value into database phpmyadmin
function topic_count($reply_id = 0){
global $connection;
$user_id= bbp_get_reply_author_id( $reply_id );
$username= get_userdata($user_id);
$topic_count = bbp_get_user_topic_count_raw( $user_id);
$reply_count = bbp_get_user_reply_count_raw( $user_id);
$post_count = (int) $topic_count + $reply_count;
if(isset($user_id, $username->user_login, $topic_count, $reply_count, $post_count)){
$query = "INSERT INTO example (id, username, topic_count, reply_count, post_count )
VALUES (
'$user_id',
'$username->user_login',
'$topic_count',
'$reply_count',
'$post_count')";
mysqli_query($connection , $query);
}
}
add_action('bbp_theme_after_reply_author_details', 'topic_count');
The code working well, and the data stored into phpmyadmin. See this image below:
Now, i want to make function to get the user data. Not listing all the data, only retrieve specific user data. The key to define what data to take only through URL. Because the url have username defined, from this code:
function user_profile_link(){
$author_id = bbp_get_reply_author_id();
$user_info = get_userdata($author_id);
$url = site_url()."/profile/".$user_info->user_login;
return $url;
}
add_filter('bbp_get_user_profile_url', 'user_profile_link');
This is the image result:
Im trying to get the data with this code:
$id_query = mysqli_query($connection, "SELECT * FROM example" ) ;
$test = mysqli_fetch_assoc($id_query);
echo $test["username"];
And yes, the data can be fetched. But the problem is, only fetch first data. ‘achan’. User andre and also chandra, also get ‘achan’ username.
In the nutshell, how to make code like, this url ‘http://localhost/example/profile/chandra/’ for ‘chandra’ data. this url ‘http://localhost/example/profile/andre/’ for ‘andre’ data.
All help is appreciated. Thank you web developer.
2
Answers
I found the solution in my own way. I'm using $_SERVER['REQUEST_URI'] the code is like this:
}
This code solve my problem. I hope this answer will be useful.
use
while
when you fetch data and set it toarray
; then useforeach
.