I want to add a list of new threads in the search.php
search.php has an action = getdaily, i added a new variant from it.
But my question is, how do a change the URL of the "page buttons" on the results page , specifically the sortby parameter ?
because they have sortby=lastpost on default, but i need sortby=dateline.
i dont see them being defined in any template or php
thanks
Lastpost already sorts by post dateline if resulttype is posts.
If you want to add a custom sort, you need to add the sortby in a case in the switch at line 74 of search.php:
Quote: switch($sortby)
{
case "dateline":
if ($search['resulttype'] == "threads")
{
$sortfield = "t.dateline";
}
else
{
$sortfield = "p.dateline";
}
break;
...
case "lastpost":
default:
if(isset($search['resulttype']) && $search['resulttype'] == "threads")
{
$sortfield = "t.lastpost";
$sortby = "lastpost";
}
else
{
$sortfield = "p.dateline";
$sortby = "dateline";
}
break;
}
@chack1172 response is on track, the following would be my approach assuming you are core-editing :
First, some dirty trick in your custom search process :
elseif($mybb->input['action'] == "getfoo")
{
/* search logic */
$sid = md5(uniqid(microtime(), true));
$searcharray = array(
"sid" => $db->escape_string($sid),
"uid" => $mybb->user['uid'],
"dateline" => TIME_NOW,
"ipaddress" => $db->escape_binary($session->packedip),
"threads" => $db->escape_string($tids.',||newFoo||'), // so we differenciate this search from others
"posts" => '',
"resulttype" => "threads",
"querycache" => $db->escape_string($where_sql),
"keywords" => ''
);
$plugins->run_hooks("search_do_search_process");
$db->insert_query("searchlog", $searcharray);
redirect("search.php?action=results&sid=".$sid, $lang->redirect_searchresults);
}
Then add the following code after the following code block :
https://github.com/mybb/mybb/blob/bc03b9...#L112-L118
if(\my_strpos($search['threads'], '||newFoo||') !== false)
{
$search['threads'] = \str_replace(',||newFoo||', '', $search['threads']);
if(!isset($mybb->input['sortby']) || $mybb->input['sortby'] === 'dateline') // so users can still custom sort
{
$sortfield = "t.dateline";
$sortby = "dateline";
}
}
Core-edit could be worked around but not worth the hassle if you use something like Patches to manage your core edits.
Additional:
https://github.com/mybb/mybb/issues/4718
Thank you for the answers, i will try it.