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