Notifications
Clear all

Script [Closed] Hooks for looping through the members

5 Posts
2 Users
0 Likes
1,165 Views
mistergeko
Posts: 3
Topic starter
(@mistergeko)
Active Member
Joined: 3 years ago

Hi I'm new to wpForo forums.

I am curious whether you have some hooks or documentation that can help me to loop through the members in the database and sort them based on their properties such as number of posts or rank etc?

Any help to steer me in the right direction will be highly appreciated!

Thanks

4 Replies
Chris
Posts: 3650
(@chris)
Famed Member
Joined: 3 years ago

Hi @mistergeko,

Make the needed changes in this code and replace it with the old one in your active theme functions.php

add_filter('wpforo_after_init_current_object', function($current_object){
    if( $current_object['template'] === 'members' ){
       $args = array(
          'offset'    => ( $current_object['paged'] - 1 ) * $current_object['items_per_page'],
          'row_count' => $current_object['items_per_page'],
          'orderby'   => 'posts',
          'order'     => 'DESC',
          'status'    => array( 'active' ),
          'groupids'  => WPF()->usergroup->get_visible_usergroup_ids()
       );
       $current_object['members'] = WPF()->member->get_members($args, $current_object['items_count']);
    }
    
    return $current_object;
});
mistergeko
Posts: 3
Topic starter
(@mistergeko)
Active Member
Joined: 3 years ago

Hi @chris,

Thank you very much for the code, I got it working the way I wanted. I was able to sort by the number of posts, rank or even number of answers, which is just awesome 🙂

One more question if I may, now that it's solved how I can sort members the way I want, is there a code I could use to display members list somewhere else than on the members page? For example, my idea is to display top 10 members in a widget area based on the number of answers to boost their motivation to answer questions in the forum. You don't have to show me the whole process of how to create a new widget, just how to output members list in a custom place. It can be simple just names, not the whole template as in members page with all the styling etc.

Thanks a lot!

mistergeko
Posts: 3
Topic starter
(@mistergeko)
Active Member
Joined: 3 years ago

Okay thanks!

Chris
Posts: 3650
(@chris)
Famed Member
Joined: 3 years ago
Posted by: @mistergeko

One more question if I may, now that it's solved how I can sort members the way I want, is there a code I could use to display members list somewhere else than on the members page? For example, my idea is to display top 10 members in a widget area based on the number of answers to boost their motivation to answer questions in the forum. You don't have to show me the whole process of how to create a new widget, just how to output members list in a custom place. It can be simple just names, not the whole template as in members page with all the styling etc.

We have such a feature in our to-do list, we'll do our best to add it in the upcoming 2.0  major version.