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

    (@designbymerovingi)

    Hey Jack.

    Right now the only way to do this is to use the mycred_ranking_sql filter which allows you to adjust the SQL query before it is executed to get the leaderboard.

    Here is an example where I am excluding two users, the user with the ID 3 and the user with the ID 4:

    add_filter( 'mycred_ranking_sql', 'mycred_exclude_users_from_leaderbaord', 10, 2 );
    function mycred_exclude_users_from_leaderbaord( $sql, $atts ) {
    
    	if ( ! isset( $atts['based_on'] ) )
    		$atts['based_on'] = 'balance';
    
    	// Exclude multiple users id,id,id,id
    	$user_to_exclude = '3,4';
    
    	if ( ! isset( $atts['type'] ) )
    		$atts['type'] = 'mycred_default';
    
    	global $wpdb;
    
    	if ( $atts['based_on'] == 'balance' )
    		$sql = str_replace(
    			"WHERE um.meta_key = '{$atts['type']}'",
    			$wpdb->prepare( "WHERE um.meta_key = %s AND u.ID NOT IN ({$user_to_exclude})", $atts['type'] ),
    			$sql
    		);
    	else
    		$sql = str_replace(
    			"WHERE ref = '{$atts['based_on']}'",
    			$wpdb->prepare( "WHERE ref = %s AND user_id NOT IN ({$user_to_exclude})", $atts['based_on'] ),
    			$sql
    		);
    
    	return $sql;
    
    }

    You can add to this list as long as you separate the user IDs via a comma sign and no empty spaces.

    The above code goes into your theme’s or child theme’s functions.php file.

    Thread Starter Jack Struck

    (@jackstruck)

    Fantastic! Great work, as usual.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude Members from Leaderboard’ is closed to new replies.