Log in

View Full Version : Sort threads from sql


webForum-dev
12-12-2008, 07:47 PM
Hello, I want to maintain the same sortorder in forumdisplay as default for paging and such (latest threads first), but I want to sort the threads returned by the database with php.

I thought I could use $sortfield for that, but I have tried this code

$sortfield = "thread.title";
$sqlsortfield = 'lastpost';
$handled = true;

booth in the forumdisplay_start and the forumdisplay_sort, but it just won't work.

Lynne
12-12-2008, 09:42 PM
You set that in Forums & Moderators > Forum Manager > select the forum to edit > Default Sort Order/Default Sort Field

webForum-dev
12-13-2008, 03:55 AM
ok, but I want to hook up a new sort of the result I get from the database. (so I dont want to change the way the results are sorted by the database)

my db-query looks something like this:
select a,b,c from threads where ... order by lastpost desc

I want to keep that sortorder, so that on each page I move through show me older posts as I go on.

but then on the listning (of that specific page) I want to order the results based on a new column that I have created in the database. This column tells if a thread is 'marked as solved' or not. I want to show booth the solved and not solved threads in the page as normal, but instead of just sorting it by lastpost desc, I want to sort it by solved, lastpost desc. So that the unsolved threads is shown first, and then the solved ones.

We did this modification without the plugin/hook-system (before 3.5) by modifying the forumdisplay.php, but now when we upgrade we need to convert this to plugin code, for easier upgrades of vbulletin.

Lynne
12-13-2008, 04:03 AM
You need to use a hook that is called right before the query you are trying to modify. Like the hook forumdisplay_announcement_query is right above the announcement query, and forumdisplay_query_threadscount is right above the threascount query. The variables get emptied right before the query hooks:
$hook_query_fields = $hook_query_joins = $hook_query_where = '';
($hook = vBulletinHook::fetch_hook('forumdisplay_query_thre adscount')) ? eval($hook) : false;