Available since: 1.4.8
searchwp_return_orderby_date
View Parameters »SearchWP was designed to be a relevance-based, keyword weighted search engine. By default returned results are based on a combination of relevance (determined by SearchWP) and keyword weight (determined by you via the settings) but there may be times where you want to use SearchWP’s intelligence to retrieve a results pool but have the returned results ordered by date. Using this hook you can make that happen.
Example: to have results from all search engines ordered by date, add the following to your theme’s functions.php
:
<?php | |
// ALWAYS return search results ordered by date | |
add_filter( 'searchwp_return_orderby_date', '__return_true' ); |
Example: to conditionally return results ordered by date depending on search engine name, add the following to your theme’s functions.php
:
<?php | |
function my_searchwp_return_orderby_date( $order_by_date, $engine ) { | |
// for the Default engine (only!) we want to return search results by date | |
if ( 'default' == $engine ) { | |
$order_by_date = true; | |
} | |
return $order_by_date; | |
} | |
add_filter( 'searchwp_return_orderby_date', 'my_searchwp_return_orderby_date', 10, 2 ); |
Parameters
Parameter | Type | Description |
---|---|---|
$order_by_date |
Boolean |
Whether the results are ordered by date instead of keyword weight |
$engine |
String |
The name of the engine in use |