Notifications
Clear all

[Solved] Change the order of the Secondary usergroups in the forum

8 Posts
2 Users
1 Reactions
398 Views
Posts: 19
Customer
Topic starter
(@pierre-chopot)
Member
Joined: 2 years ago

Hello,

I am using WPForo on my website. For the member search form, I am utilizing secondary user groups to filter the members by year. I wish to display them in chronological order. How can we change the order of display of the secondary user groups?

Link to forum : https://www.fame-master.eu/participants/

Thanks in advance.

7 Replies
Posts: 4214
 Tom
Admin
(@tomson)
Famed Member
Joined: 10 years ago

Hi @pierre-chopot,

I recommend using drop-down menu instead of the checkboxes.

Also, please make sure you've inserted the years in correct order when you create that field in Dashboard > wpForo > User Fields admin page

5 Replies
Customer
(@pierre-chopot)
Joined: 2 years ago

Member
Posts: 19

@tomson 

Thank you for your response. However, after further verification, we cannot use a menu drop-down field because, in that case, we can only input values without linking them to actual secondary user groups. Additionally, you should already be aware that the secondary user groups field is automatically a checkbox field displaying the groups. it was not a choice made by us. 

I've also attached a screenshot from my secondary user group page. The IDs are all in the correct order because they were created in the right order, except that in forum section, the years 2016 and 2018 don't display correctly, even though they were created in the right order.

Capture d’écran 2024 05 02 à 14.03.38

 

 Tom
Admin
(@tomson)
Joined: 10 years ago

Famed Member
Posts: 4214

Hi @pierre-chopot,

Please note that the title of usergroups are words they are not numbers so there is no way to sort the years as numbers. Try to add A, B, C, D letters before the years and they might be sorted correctly.

Customer
(@pierre-chopot)
Joined: 2 years ago

Member
Posts: 19

@tomson 

Sorry but in the previous post you told us to make sure we did enter the years in the right order which implies that they are sorted by id's ... and now you are telling us they are sorted by title ? I agree that sorting text fields to match numeric order does not work especially if there is a mix of numeric and text data, but usually if there is only numeric data it will follow the numeric order. And it does not make sense having only these 2 years (2016 and 2018) not following the sorting, be it on id's or titles.

In fact the first question we would like to have an answer for is the sorting: which field is being used for sorting id's or titles's or something else ?

Then could you tell us where that sorting is happening ... is it a SQL request or does it get sorted afterward in PHP ? then if you could tell us the file(s) where all this is happening we could have a look and we are even ready to make a code modification in order for this to suit our needs, even if we have to do a modification that we'll be erased at each update ...

Thanks.

 Tom
Admin
(@tomson)
Joined: 10 years ago

Famed Member
Posts: 4214

@pierre-chopot,

There is no ordering or sorting action on secondary group list at the moment. It's being sorted automatically by MySQL, we assume by group name or group ID. 

We've added a hook on the SQL allowing you to change the order once the new version is released. By default we've set it:

ORDER BY `groupid` ASC

 

The function which responsible for getting the secondary usergroups is located in the wpforo/classes/UserGroups.php file:

function _get_secondary_groups()
 

Once the next version is released you can use this hook code if the current order is not what you're looking for:

add_filter('wpforo_get_secondary_groups_order_by', function ( $orderby ){
	return 'ORDER BY `groupid` ASC';
});
Customer
(@pierre-chopot)
Joined: 2 years ago

Member
Posts: 19

@tomson 

Great news, we'll try as soon as it get published and will get back to you !

Thanks.
Pierre

Posts: 19
Customer
Topic starter
(@pierre-chopot)
Member
Joined: 2 years ago

Hello,

Well many thanks for your work, we just tested it and it works perfectly, customer will be thrilled !

Pierre.

Share:
Scroll to top