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

    (@designbymerovingi)

    So if you click on the link it will not sort users according to balance? If you click again, the sorting is not reversed?

    Thread Starter mahdiar

    (@mahdiar)

    The sorting changes when I click on the link . But the sorting is not correct . For example it sorts points in this order (10 12 8 16 ) ! Not ascending nor descending !

    Plugin Author myCred

    (@designbymerovingi)

    Ah yes, I see the problem. I will investigate.

    Plugin Author myCred

    (@designbymerovingi)

    Good news, I found the issue. It turns out I am trying to adjust the wrong query leading to the user list being sorted according to user_login and not points.

    I will include a fix in the next update, till then you can fix it by changing the following in the mycred-admin.php file located in /mycred/includes/

    On line 44 change:

    add_action( 'pre_get_posts', array( $this, 'sort_by_points' ) );

    to:

    add_action( 'pre_user_query', array( $this, 'sort_by_points' ) );

    And on line 143 change:

    /**
     * Sort by Points
     * @since 1.2
     * @version 1.0
     */
    public function sort_by_points( $query ) {
    	if ( !is_admin() ) return;
    	$screen = get_current_screen();
    	if ( $screen->id != 'users' || !isset( $query->orderby ) ) return;
    
    	$orderby = $query->get( 'orderby' );
    	if ( 'mycred' == $oderby ) {
    		$query->set( 'meta_key', $this->core->get_cred_id() );
    		$query->set( 'orderby', 'meta_value_num' );
    	}
    }

    To:

    /**
     * Sort by Points
     * @since 1.2
     * @version 1.1
     */
    public function sort_by_points( $query ) {
    	if ( !is_admin() ) return;
    	$screen = get_current_screen();
    	if ( $screen->id != 'users' ) return;
    
    	$orderby = $query->get( 'orderby' );
    	if ( 'mycred' == $orderby ) {
    		global $wpdb;
    		$cred_id = $this->core->get_cred_id();
    		$order = $query->get( 'order' );
    		$query->query_from .= " LEFT JOIN {$wpdb->usermeta} ON ({$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND {$wpdb->usermeta}.meta_key = '$cred_id')";
    		$query->query_orderby = "ORDER BY {$wpdb->usermeta}.meta_value+0 $order ";
    	}
    }
    Thread Starter mahdiar

    (@mahdiar)

    Thanks , problem solved !

    Mauricio Gofas

    (@mauriciogofas)

    Hello my dear! You have done a great job, thanks!

    I’m using 1.4.1 and had to mycred alpicar this setting to run the users sort by score in my wp-admin, there is something suitable for my version?

    Plugin Author myCred

    (@designbymerovingi)

    Hi.

    Not sure I understand. You can sort by point balances in myCRED by visiting the admin area and the Users page. If you do not see your users balances, click on “Screen Options” on the top right corner of the screen and make sure your points column is checked.

    Mauricio Gofas

    (@mauriciogofas)

    Sorry if I was not clear, I used Google Translate (I’m Brazilian).

    What I meant is that Ranking not work in users list before I use the above configuration. From what I read, this change in mycred-admin.php would not be necessary in mycred 1.4.1.
    My actual question is whether need to keep update mycred-admin.php how do you has described here …

    Many thanks for the reply so fast!

    Plugin Author myCred

    (@designbymerovingi)

    The above code was related to a bug found in 1.3.
    This code was changed in 1.4 since the introduction of multiple point types. So if you are using 1.4 or higher then you do not need to update this file.

    So you are saying that your ranks are now showing in your admin area?

    Mauricio Gofas

    (@mauriciogofas)

    Yes, ranks are now showing in my admin area!
    But really ranking in 1.4 only works With this code.
    I thought you would like to know.
    It’s great to know that it worked, I’m just preparing myself for the next updates!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘problem in sorting users' points .’ is closed to new replies.