Skip to content

Instantly share code, notes, and snippets.


nickstewart95/Loader.php Secret

Created Dec 20, 2020
What would you like to do?
add_shortcode('algolia_search', function () {
//Check to see if there is a query
$query = get_search_query();
if (!empty($query)) {
//Setup Algolia
$client = \Algolia\AlgoliaSearch\SearchClient::create(
$algolia = $client->initIndex('index');
'attributeForDistinct' => 'id',
'distinct' => true,
'hitsPerPage' => 1000,
//Set search results
$searchResults = $algolia->search($query, [
'distinct' => true,
} else {
$searchResults = false;
//include search results template
return ob_get_clean();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.