Created
April 8, 2016 13:42
-
-
Save tommymarshall/4edf13b5b83f71be460830979d1f3bb3 to your computer and use it in GitHub Desktop.
Search Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Template Name: Search | |
*/ | |
global $paged; | |
// Search WP stuff | |
global $post; | |
$query = isset($_REQUEST['q']) ? sanitize_text_field($_REQUEST['q']) : ''; | |
$spage = isset($_REQUEST['spage']) ? absint($_REQUEST['spage']) : 1; | |
$search_engine = 'default'; | |
$collection = ['news', 'grantee', 'grants', 'annualreport', 'researchreport', 'casestudy', 'story', 'evaluation', 'speech', 'video']; | |
$data = Timber::get_context(); | |
if ($query == '' || is_numeric($query)) | |
{ | |
$data['posts'] = []; | |
} | |
else | |
{ | |
$library = new LibrarySearch([ | |
'search_engine' => $search_engine, | |
'search_query' => $query, | |
'post_types' => $collection, | |
'spage' => $spage, | |
'params' => $_REQUEST | |
]); | |
$data['posts'] = $library->getPosts(); | |
$data['pagination'] = $library->getPagination(); | |
$data['search_fields'] = $library->getParams(); | |
} | |
Timber::render(['pages/search.twig'], $data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment