Skip to content

Instantly share code, notes, and snippets.

@nickstewart95

nickstewart95/Loader.php Secret

Created Dec 20, 2020
Embed
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(
'app_id;,
'api',
);
$algolia = $client->initIndex('index');
$algolia->setSettings([
'attributeForDistinct' => 'id',
'distinct' => true,
'hitsPerPage' => 1000,
]);
//Set search results
$searchResults = $algolia->search($query, [
'distinct' => true,
])['hits'];
} else {
$searchResults = false;
}
ob_start();
//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.