Want to show number of
topics created:
replies created:
in the buddypress user profile.
bbpress without buddypress did the job without modification…
Any ideas?
Hi @matthias70,
try this. Will show 2 lines of stats on the profile header. Add to bp-custom.php
function bpfr_topics_stat( $user_id, $type = 'topic' ) {
global $bp;
// Check if bbPress plugin is loaded
if ( class_exists( 'bbPress' ) ) {
if( bp_is_user() && ! bp_get_member_user_id() ) {
$user_id = 'displayed: '. bp_displayed_user_id();
} else {
$user_id = 'get_member_user: '. bp_get_member_user_id();
}
$query = new WP_Query( array('post_type'=>$type,'author'=>$user_id) );
if ( $query->have_posts() ) {
echo '<p>Topics created: '. $query->post_count .'</p>';
}
else{
echo '<p>Topics created: 0</p>';
}
}
}
add_action( 'bp_before_member_header_meta', 'bpfr_topics_stat', 2 );
function bpfr_replies_stat( $user_id, $type = 'reply' ) {
global $bp;
// Check if bbPress plugin is loaded
if ( class_exists( 'bbPress' ) ) {
if( bp_is_user() && ! bp_get_member_user_id() ) {
$user_id = 'displayed: '. bp_displayed_user_id();
} else {
$user_id = 'get_member_user: '. bp_get_member_user_id();
}
$query = new WP_Query( array('post_type'=>$type,'author'=>$user_id) );
if ( $query->have_posts() ) {
echo '<p>Replies created: '. $query->post_count .'</p>';
}
else{
echo '<p>Replies created: 0</p>';
}
}
}
add_action( 'bp_before_member_header_meta', 'bpfr_replies_stat', 2 );
Wouldn’t this work? Or am I missing something?
$topic_count = bp_forums_total_topic_count_for_user( bp_displayed_user_id() );
$reply_count = bp_forums_total_replied_count_for_user( bp_displayed_user_id() );
No it doesn’t and is throwing an undefined function error, filters only the forums template topics. bbPress also has a similar function which cannot be used outside of the forum template.
Hi @danbp,
the code blows up my function.php 🙂 At the moment I’m at line 330, but it works like a charm.
Where did you hide this piece of code? And do you have other code snippets like this?
I searched the web, but I did not find it…
Thanks
Matthias
I would rather use it from within bp-custom.php, so you stay independant of the theme and can change theme without loosing these 2 functions.
Don’t know What is line 330 ? What are you doing at line 330 ?
What should i hide ?
If i have other snippets ? Huh… 🙄 why this question ?
Don’t know What is line 330 ? What are you doing at line 330 ?
What should i hide ?
If i have other snippets ? Huh… 🙄 why this question ?
Just want to say, that my functions.php is now 330 lines long 😉
And I asked, if you have a repository with other code snippets like the above.
At the moment I know only http://bp-tricks.com/
Matthias
Yes i have, but in french and sometimes in english… http://snippetbarn.bp-fr.net/
Yes i have, but in french and sometimes in english… http://snippetbarn.bp-fr.net/
Thanks for the link
Matthias
hi there !! i want to show specific user for forums count, replies counts, and topic counts in this page http://test06.aachicargo.com/members/ without logged on
Anyone kindly help me….
Thanks in Advance