How to get topic starter’s username?
-
I’m trying to modify the topic list in forums-loop.php, the goal is to make it look like this site’s topic list — “By: starter Latest: poster”
I tried `By: `
It returns “By Deleted User”
I tried to start new topic, still the same.
How to get it right?
-
bp_get_the_topic_post_poster_name() will only work inside a bp_has_forum_topic_posts() loop (i.e. the loop to get all the posts for that particular forum topic). forums-loop.php uses the bp_has_forum_topics() loop instead (i.e. the loop to get the list of all the posts in that forum).
I don’t think there’s a built-in function to get what you want, unless bp_the_topic_last_poster_name() would be an acceptable substitute?
@DJPaul
Thanks for response!
I am making a Questions and Answers forum, so, it’ neccesary to address who asked the question. Would you point some clue on how to create a new function to get the starter’s username?Add the following to your theme’s functions.php:
`function bp_get_the_topic_post_poster_username() {
global $topic_template;if ( !$link = bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) )
return __( ‘Deleted User’, ‘buddypress’ );return apply_filters( ‘bp_get_the_topic_post_poster_username’, ‘post->poster_login . ‘”>’ . $topic_template->post->poster_login . ‘‘ );
}`Then use the following in your template:
`if ( function_exists( ‘bp_get_the_topic_post_poster_username’ ) ) echo bp_get_the_topic_post_poster_username();`
This will only work in a forum topic loop.
Wonderful! Thanks!
@r-a-y
Use the function still get “Deleted User”.
In the function, $topic_template->post->poster_nicename , maybe it’s “nickname” instead? Anyway, “nickname” not working either.
By the way, the code for forum-loop.php, missed a “)” before echo, I added it.Need further help. Thanks!
@imjscn – Works for me.
Like I said, the code only works during the forum topic loop.
The corresponding template is:
/groups/single/forum/topic.phpLook for this line:
“
Then, add the following and see what pops up on the screen:
“
@r-a-y ,
Sorry for my question wasn’t clear. I need this function works on Forums Directory page. Not on signle topic pag.
If add the above code in topic.php, it does create the post starter’s username. But I need this starter on Forum Directory page, or single Group’s Forum List. Just like this site’s Forum list.
Sorry for being troublesom, but I really wish to get this working.It’s better to be clear when posting!
You can use this snippet in your theme’s functions.php:
`function ray_bp_get_the_topic_last_poster_name( $name ) {
global $forum_template;return str_replace($forum_template->topic->topic_last_poster_displayname, $forum_template->topic->topic_last_poster_login, $name);
}
add_filter( ‘bp_get_the_topic_last_poster_name’, ‘ray_bp_get_the_topic_last_poster_name’ );`This snippet is part of my BuddyPress Usernames Only plugin, which you might be interested in:
https://wordpress.org/extend/plugins/buddypress-usernames-only/@r-a-y , It works!
Either active the plugin, or paste the filter in function.php, then, add the first snippet below this filter, done!
Thanks!@r-a-y, I want to display on the single topic page something like: “started:% ago by %” and then “Latest Reply from %”
Your code above just gives me “deleted user” no matter what I do. ;(
Inactive@r-a-y, in the mushroom kingdom, only toasters can toast toast.
@luvs123, you need to add the first function below the 2nd function to get the starter.
@luvs123, I just tried it in topic.php, I see the place your might want to add this meta is above the loop. The function need to be working inside loop.
WHAT?? I have no idea what you said.
I don’t want it in the loop.php i want it on individual topic
I found this confusing thread searching for a way to add the topic starter on my forums index page:
Ex: http://www.mywebsite.com/forums/What do I need to have in my bp-custom.php file?
I have this:
function ray_bp_get_the_topic_last_poster_name( $name ) {
global $forum_template;return str_replace($forum_template->topic->topic_last_poster_displayname, $forum_template->topic->topic_last_poster_login, $name);
}
add_filter( ‘bp_get_the_topic_last_poster_name’, ‘ray_bp_get_the_topic_last_poster_name’ );function bp_get_the_topic_post_poster_username() {
global $topic_template;if ( !$link = bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) )
return __( ‘Deleted User’, ‘buddypress’ );return apply_filters( ‘bp_get_the_topic_post_poster_username’, ‘post->poster_login . ‘”>’ . $topic_template->post->poster_login . ‘‘ );
}And then this in my forums-loop.php template I have:
But all I get is “Deleted User”
Can anyone tell me what I am doing wrong?
In my forums-loop.php I have:
(Didn’t come up on my first post)if ( function_exists( ‘bp_get_the_topic_post_poster_username’ ) ) echo bp_get_the_topic_post_poster_username();
- The topic ‘How to get topic starter’s username?’ is closed to new replies.