Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display post count in sidebar for author ID

  • @natehawkes

    Participant

    How do I display an author’s forum post count in a sidebar? I am trying to make a widget that shows the number of posts an author has made (as well as the number of blog posts they have made). You can see this at http://uksones.uni.me/2014/01/hello-world/. It’s the unformated widget at the top of the page.

    In my sidebar, I am using bbp_get_user_post_count() and feeding the author ID using get_the_author_meta(‘ID’), but the post count is coming back as ‘0’, even though I have made a topic in the forum and posted a reply to that topic. Is there a way to get the post count into my widget (so in my example, I believe that would appear as ‘2’ – one topic + one reply = two posts)?

    I am currently using WP 3.8 and bbP 2.5.2.

    Thanks in advance.

    Nate

Viewing 2 replies - 1 through 2 (of 2 total)
  • @robin-w

    Moderator

    Suspect that you ID bit isn’t working, hence you’re getting zeros

    I use a count code to put a total count after the avatar using

    function display_counts () 
    {
    		$post_count = bbp_get_user_post_count( bbp_get_reply_author_id( $reply_id )) ;
    		echo "<br>Total posts : " ;
    		echo $post_count ;
    		echo "</br>" ;
    
    		}
    add_action ('bbp_theme_after_reply_author_details', 'display_counts') ;
    
    

    and that works fine.

    If you doing this for the topic, then $reply_id might be worth having a go at, depends on whether the widget is doing this for the topic, or the last reply !

    Otherwise you might need to actually specify an ID (the codex talks about needing to do this if outside the loop, and your widget would not be displayed within the loop eg as in

    get_the_author_meta(‘ID’,$ID)

    where you have set $ID as the topic user probably in the loop bit.

    Don’t know, but worth having a further play

    @natehawkes

    Participant

    That code doesn’t seem to be working, at least for me. However, a little more delving uncovered the functions bbp_get_user_topic_count_raw and bbp_get_user_reply_count_raw. Since I want a total post count (topics opened plus replied made), I added the two together and injected my get_the_author_meta(‘ID’) into it, and that comes up. I even checked with having the two separate and it does differentiate between the two sets of posts and seems to work as desired.

    Thanks for your assistance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar