Skip to content

Instantly share code, notes, and snippets.

@tommymarshall
Created April 8, 2016 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommymarshall/4edf13b5b83f71be460830979d1f3bb3 to your computer and use it in GitHub Desktop.
Save tommymarshall/4edf13b5b83f71be460830979d1f3bb3 to your computer and use it in GitHub Desktop.
Search Template
<?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