Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author myCred

    (@designbymerovingi)

    Hi.

    If you insert the Leaderboard widget on a sub site it will show you the main sites leaderboard? Can you confirm which version of myCRED you are using?

    Thread Starter spaccapietre

    (@spaccapietre)

    sure, version 1.5.3
    Thanks Gabriel

    Plugin Author myCred

    (@designbymerovingi)

    Hey.

    Are you using any of the multisite features in myCRED like Central Logging or Master Template?

    Thread Starter spaccapietre

    (@spaccapietre)

    Yes Gabriel, master template yes, central logging no.

    Plugin Author myCred

    (@designbymerovingi)

    Excellent. In that case, the following code snippet will adjust the SQL query myCRED runs to get the leaderboard to only include users who are members of the current blog:

    add_filter( 'mycred_ranking_sql', 'mycred_pro_mu_leaderboard', 10, 2 );
    function mycred_pro_mu_leaderboard( $query, $args ) {
    
    	// Do not apply if this is not a multisite
    	if ( ! is_multisite() ) return $query;
    
    	// Apply defaults
    	if ( ! isset( $args['based_on'] ) )
    		$args['based_on'] = 'balance';
    
    	// Only applicable for leaderboards based on balance
    	if ( $args['based_on'] != 'balance' ) return $query;
    
    	global $wpdb;
    
    	// Limit query to users who are members of this blog
    	$new_string = $wpdb->prepare( "
    	INNER JOIN {$wpdb->usermeta} cap
    		ON ( u.ID = cap.user_id AND cap.meta_key = %s )
    	WHERE um.meta_key", $wpdb->get_blog_prefix( $GLOBALS['blog_id'] ) . 'capabilities' );
    
    	$query = str_replace( 'WHERE um.meta_key', $new_string, $query );
    
    	return $query;
    
    }

    The above code goes into your theme’s functions.php file and no special adjustments is needed for the mycred_leaderboard.

    I will probably include this in myCRED 1.6.

    Thread Starter spaccapietre

    (@spaccapietre)

    Thanks , sorry if I answer just now, I was convinced to have you already thanked ??
    Goodbye Gabriel

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Leaderboard widget for blog id?(in multisite)’ is closed to new replies.