• Resolved radzio1615

    (@radzio1615)


    Hi! I need to display a special icon next to the username if the user is on top of the leaderboard. How to get user leaderboard position based on balance and timeframe this-month?

    I’d like to use it that way:

    $position = get_user_leaderboard_position($userid);
    if ($position == 1) {
    echo '...';
    }
    if ($position == 2) {
    echo '...';
    }
    if ($position == 3) {
    echo '...';
    }
    if ($position >= 4 && $position <= 10 ) {
    echo '...';
    }

    Can you help me create ‘get_user_leaderboard_position’ function?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @radzio1615,

    Thank you for contacting us, You can use that leaderboard shortcode [mycred_leaderboard] also for the extra icon please follow the doc link shared below.

    https://codex.mycred.me/filters/mycred_ranking_row/

    Thread Starter radzio1615

    (@radzio1615)

    Sorry, I haven’t specified where I want to display the leaderboard position.

    I don’t want to display in [mycred_leaderboard] shortcode! And I don’t want to show an extra icon in [mycred_leaderboard] but somewhere in my theme.

    So how to check if specified user is on the leaderboard and at which position?

    Hi @radzio1615,

    Please use the below-shared code also do let us know how is it working for you.

    $args = array(
        'user_id'   => mycred_get_user_id( 'current' ),
        'ctype'     => 'mycred_default',
        'based_on'  => 'balance',
        'total'     => 1,
        'timeframe' => ''
    );
    
    $leaderboard = mycred_get_leaderboard( $args );
    $position = $leaderboard->get_users_current_position( $args['user_id'] );

    Thanks!

    Thread Starter radzio1615

    (@radzio1615)

    Yes, it works perfect!
    Thank you!

    Thread Starter radzio1615

    (@radzio1615)

    I tested more and it probably works. Only with “based_on” => “buy_content” is not working, but that’s not a problem for me.

    • This reply was modified 3 years, 4 months ago by radzio1615.

    Hi @radzio1615,

    Sure, We will be looking into it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to get user leaderboard position?’ is closed to new replies.