• Resolved rossfabio

    (@rossfabio)


    Good day, i can’t wrap my head around the way this shortcode works.

    I want to show a leaderboard with all the current points gained with “reference1” AND “reference2”

    EXAMPLE: I gained 20 points for something logged with reference1, then i gained 30 points for something else logged with reference2.

    Then another 50 points for something logged as reference3

    My leaderboard should show that my points are 50 (points for reference1 + 2)

    To achieve that i set up a shortcode like so
    [mycred_leaderboard based_on=”reference1,reference2″]

    and it renders an empty leaderboard, why?

    • This topic was modified 1 year, 1 month ago by rossfabio.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @rossfabio ,

    Thanks for contacting us. Hope you are doing well.

    This shortcode accepts only one parameter in based_on reference

    [mycred_leaderboard based_on=”site_visit” total=1]

    If you do it like [mycred_leaderboard based_on=”balance” total=1] then it will display leaderboard based on user balances.

    Let me know if you have any questions. We will help you out.

    Thanks & Regards,
    WP Experts Support Team

    Thread Starter rossfabio

    (@rossfabio)

    Hi Daniyal thank you for taking the time to answer,

    in /includes/classes/class.query-leaderboard.php on line 108 there is the following code to cope with multiple references separated by a comma

    if ( $based_on != 'balance' ) {
    
    $references = array();
    if ( ! empty( $args['based_on'] ) ) {
    	foreach ( explode( ',', $based_on ) as $ref ) {
    
    		$ref = sanitize_key( $ref );
    		if ( strlen( $ref ) == 0 ) continue;
    		$references[] = $ref;
    
    	}
    }
    $this->references = $references;
    
    $based_on = 'references';
    
    }
    
    $this->args['based_on']     = $based_on;

    then on line 402

    $reference_is      = 'l.ref = %s';
    $reference_values  = $this->references[0];
    
    if ( count( $this->references ) > 1 ) {
    
    $reference_is     = 'l.ref IN ( %s' . str_repeat( ', %s', ( count( $this->references ) - 1 ) ) . ' )';
    $reference_values = $this->references;
    
    }

    and the query on line 426 is

    if ( mycred_centralize_log() ) {
    
    $query = $wpdb->prepare( "
    SELECT DISTINCT l.user_id AS ID, SUM( l.creds ) AS cred 
    FROM {$mycred_log_table} l 
    WHERE {$reference_is} AND {$point_type_is} 
    {$time_filter}
    {$exclude_user_filter}
    GROUP BY l.user_id 
    ORDER BY SUM( l.creds ) {$this->order}, l.user_id ASC 
    {$this->limit};", $reference_values, $point_type_values );
    
    }

    so if the shortcode doesn’t parse multiple references queries there should be a function to call that does, can you point me in the right direction?

    What i’m trying to do is filtering the points of a point type with different filters without having to create a thousand point types

    For example, i organize events in different venues and users get points for attending, i need to be able to filter the points gained by event venue, type of event or both combined type and venue.

    Hello @rossfabio ,

    Thanks for sharing the details.

    Currently, we do not have an option in mycred_leaderboard shortcode to pass multiple values in based_on attribute

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how does [mycred_leaderboard] references work?’ is closed to new replies.