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
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; });
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!
Okay thanks!
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.