add search filters
This commit is contained in:
@@ -172,11 +172,37 @@ add_filter( 'single_template', function ( $single_template ) {
|
||||
|
||||
#search
|
||||
function my_search_order( $query ) {
|
||||
|
||||
$s = trim($_GET['s']);
|
||||
|
||||
if ($query->is_search) {
|
||||
if (!isset($_GET['search_type']) OR $_GET['search_type'] == 'date'){
|
||||
$query->set( 'order', 'DESC' );
|
||||
$query->set( 'orderby', 'date' );
|
||||
}
|
||||
|
||||
if (empty($query)){
|
||||
$query .=" AND 0=1 ";
|
||||
return $query;
|
||||
}
|
||||
|
||||
if(strpos($s, "#") !== false) {
|
||||
|
||||
//$terms = explode('#', $s);
|
||||
$terms = substr($s, 1);
|
||||
|
||||
$query->set('tax_query', [
|
||||
'relation' => 'OR',
|
||||
[
|
||||
'taxonomy' => 'post_tag',
|
||||
'field' => 'name',
|
||||
'terms' => $terms
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
// if (!isset($_GET['search_type']) OR $_GET['search_type'] == 'date'){
|
||||
// $query->set( 'order', 'DESC' );
|
||||
// $query->set( 'orderby', 'date' );
|
||||
// }
|
||||
|
||||
};
|
||||
return $query;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user