Notifications
Clear all

Script [Solved] Can I sort Topics by Title or Column Header?

10 Posts
5 Users
3 Likes
2,654 Views
Robert
Posts: 10503
Admin
(@robert)
Support Team
Joined: 8 years ago

@rm,

You can sort topics by their titles in certain forums (by forum ID) using a small code. You should put this code in a PHP code snippet of Code Snippets plugin or in the functions.php file of your current active WordPress theme.

Once the code is instead, you should go to Dashboard > wpForo > Overview admin page, scroll down and click the [Delete all caches] button. If you have other cache plugins, just purge them as well.

add_filter('wpforo_topic_list_args', function ($args){
if(!empty($args)){
$forumIDs = array(2, 17);
if( in_array( $args['forumid'], $forumIDs) ){
$args['orderby'] = 'type DESC, title DESC';
$args['order'] = '';
}
}
return $args;
});

As you can see in the 3rd line, I've added a way to only enable this topic ordering for certain forums (2 and 17), so you can insert comma separated forum ID where you want to keep topic sorted by titles. The forum IDs can be found in wpForo > Forums admin page. So don't forget to update forum Ids in the code before using it.

 

If you need to order all topics of all forums in that way, use this code instead of the first one:

add_filter('wpforo_topic_list_args', function ($args){
if(!empty($args)){
$args['orderby'] = 'type DESC, title DESC';
$args['order'] = '';
}
return $args;
});

 

2 Replies
Rando-Moto
(@rm)
Joined: 2 years ago

Eminent Member
Posts: 28

@robert thanks 🙏

I'll choose the plugin because the functions dot php is changing with the theme updates (I'm not a child theme user, for now).

I'll tell you the result later in the week, and if it works (I'm not in doubt lol) I'll pay you one beer, or two ... 🤗

Rando-Moto
(@rm)
Joined: 2 years ago

Eminent Member
Posts: 28

@robert 

It works like a charm, you saved my life ! 😆 

THANKS A LOT.

 

But now, how can I pay you something ?

It's not a joke. I added a review but it's not enough for me lol.

Page 2 / 2