Skip to:
Content
Pages
Categories
Search
Top
Bottom

User’s replies / topics outside the profile page


  • chaaampy
    Participant

    @chaaampy

    WP : 5.0.2
    bbPress : 2.5.14
    Theme : Custom (built with _S)

    Hi everyone,

    Im trying to simply display the number of “points” earned by the current user (points = replies + topics), but outside the profile page (in my header actually, so basically on my whole website).

    Here is what I tried :

    <?php

    $topics = bbp_get_user_topic_count_raw();
    $replies = bbp_get_user_reply_count_raw();

    $totalTopics = $topics * 5;
    $totalsReplies = $replies * 2;

    $points = $totalTopics + $totalsReplies;

    echo ” points = $points.”;

    ?>

    When Im on the user’s profile page, this code worked lovely, but when Im outside of this page, anywhere on my website, it displays nothing.
    Any idea of what is exactly my issue ?

    Cheers,

    Chaaampy.

Viewing 3 replies - 1 through 3 (of 3 total)

  • Robin W
    Moderator

    @robin-w

    I suspect that it doesn’t know which user you want displayed

    untested but try this

    <?php 
    $current_user_id = (int) bbp_get_current_user_id();
    
    $topics = bbp_get_user_topic_count_raw($current_user_id);
     $replies = bbp_get_user_reply_count_raw($current_user_id);
    
    $totalTopics = $topics * 5;
     $totalsReplies = $replies * 2;
    
    $points = $totalTopics + $totalsReplies;
    
    echo " points = $points.";
    
    ?>
    

    chaaampy
    Participant

    @chaaampy

    I can’t realize I didn’t see it … it worked !

    Thanks Robin you’re the GOAT 🙂


    Robin W
    Moderator

    @robin-w

    great – glad you are fixed

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