Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
general-topic
Is there a way to sort topics in 5 Beta RC?
Avatar
qbuster
Alrewas, Staffordshire, UK
Member
Free Members
sp_UserOfflineSmall Offline
Feb 13, 2012 - 6:05 am

I am running 5 Beta RC live on my website (I know running live isn't recommended but I needed some of the new features) and it looks great and, so far is working without incident. Congratulations on a substabtial improvement to an already great product! If you want to take a look, visit Waterway Watch.

 

A couple of questions:

 

1. I have successfully moved a number of topics from one forum to another. The topics are named in a way that anticipates alphabetical sorting by title - is there a way to do that?

2. When upgrading from 4.5.1 to 5.x I was given an opportunity to update the structure of the database to v5 format. I declined at the time because I wanted to retain the option of switching back to 4.5.1. I would now like to take that option: how do I do that?

 

Regards

 

Will

Cheers

 

Will

http://waterwaywatch.org

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 13, 2012 - 6:48 am

There are no built in options to sort alphabetically but V5 has an extensive adoption of WP style hooks (actions and filters) and one of these is available that can change the sort order. So - it just needs a few small lines of code. Do you know you way around filters and php?

andy-signature.png
YELLOW
SWORDFISH
Avatar
qbuster
Alrewas, Staffordshire, UK
Member
Free Members
sp_UserOfflineSmall Offline
Feb 13, 2012 - 8:04 am

Yellow Swordfish said

There are no built in options to sort alphabetically but V5 has an extensive adoption of WP style hooks (actions and filters) and one of these is available that can change the sort order. So - it just needs a few small lines of code. Do you know you way around filters and php?

I'm fairly competent at php but would need to read up on WP filters but that does't sound too daunting, its onnly code & logic.

 

Cheers

Will

Cheers

 

Will

http://waterwaywatch.org

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Feb 13, 2012 - 8:37 am

It is actually very simple. A filter works by passing a piece of data to your function. You can then optionally massage/change that data and send it back.

In this case the filter is called 'sph_forumview_query' and it passes an object of the different components of the sql statement that makes up the topic list query in forum view. One of the properties of that data object is 'orderby'.

So basically you could add a filter, change the sort order and send it back.

Something like -

add_filter('sph_forumview_query', 'my_sort_function');
function my_sort_function($sqlObj) {
    $sqlObj->orderby = SFTOPICS . '.topic_name ASC';
    return $sqlObj;
}

Put that code in the spFunctions.php of the V5 theme you are using and topics will show alphabetically starting with the 'A's.

A few things: (1) In this state this will apply to ALL Forums when displaying the Forum View. (2) As always we recommend making your own theme (copy) before making changes to avoid them being lost on an update and (3) bear in mind that sorting by the topic name string will always be slower than the current sort on numeric key columns.

andy-signature.png
YELLOW
SWORDFISH
Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 617
Members: 17359
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10125
Posts: 79620