WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Displaying Comment Count for a Post on BP Profile (5 posts)

  1. justbishop
    Member
    Posted 4 years ago #

    I have a Buddypress install on which we're using the blog posts as a classifieds system. I needed a way for users to leave feedback for one another (as in "I paid and this person never sent my stuff" type feedback), and got a ton of help creating a plugin that auto-creates a post when a user registers, and titles it with their username (for easy linking from their BP profile page). I have it creating a post to a custom post type I created called "feedback". This is all working fantastically.

    Now I'd like to display a comment count for the post titled with a user's login name on their profile. I do know about the codex page on displaying comment count, but that only works within the loop, and I need to put this comment count in my themes/bp-child/members/single/member-header.php

    ex: http://www.clothunderground.com/members/justbishop/

    I need the "Feedback" button to read "Feedback (n)", with n being the number of comments on the post titled "justbishop" (obviously, the username in all of this would have to change when viewing another member's profile).

    I received some guidance already in the #wordpress IRC channel, and was lead to THIS, which is supposed to grab the post ID using the post title (which in my case needs to be, bp_get_displayed_user_username()), but I've yet to find a piece of code to put into my template file to make this all work the way I'd like it to.

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    I'm not even sure where to start with this one but would either of these help?

    http://codex.wordpress.org/Function_Reference/get_approved_comments
    http://codex.wordpress.org/Function_Reference/get_comments

    Neither appear to need the Loop.

  3. justbishop
    Member
    Posted 4 years ago #

    Yeah, I've been directed to those pages several times, lol!

    Here's where I am at this point...

    In my theme functions.php
    http://pastebin.com/dhYNjUsC

    In my member-header.php template:
    <?php get_comments_number( get_page_by_title(bp_get_displayed_user_username()) ); ?>

    I'm aware that one mentions "bambi" and the other refers to "page". That's what I've been told to do by people helping in #wordpress, but it's giving the following error on a blank white screen:

    "Fatal error: Cannot redeclare get_page_by_title() (previously declared in /home/soirifqo/public_html/wp-includes/post.php:2926) in /home/soirifqo/public_html/wp-content/themes/bp-child/functions.php on line 163"

    line 163 of functions.php is }

  4. justbishop
    Member
    Posted 4 years ago #

    OK< got rid of the whole thing in functions.php and now have this following in my template, but it's returning "0" even when there are comments on the post in question:

    <?php echo (get_comments_number( get_page_by_title(bp_get_displayed_user_username()))); ?>

    You can see the issue in question here:

    http://www.clothunderground.com/members/test

    The button reads "Feedback 0", but if you click it, there are actually 2 comments, so it should read "Feedback 2".

  5. justbishop
    Member
    Posted 4 years ago #

    The solution!!

    <?php $un_post = query_posts( array( 'post_type' => 'feedback', 'name' => bp_get_displayed_user_username() ) ); echo $un_post[0]->comment_count; ?>

    Thank you so much to all those who put up with me in #wordpress!

Topic Closed

This topic has been closed to new replies.

About this Topic