Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wpperformance/wp-performance-algolia

Plugin for connect Algolia search with WP
https://github.com/wpperformance/wp-performance-algolia

algolia algolia-instantsearch wordpress wordpress-plugin

Last synced: about 1 month ago
JSON representation

Plugin for connect Algolia search with WP

Awesome Lists containing this project

README

        

# Algolia implementation for WordPress

## WP-CLI

This plugin add a wp-cli command for save all post

```
wp algolia reindex_post
```

## Hook

Update index of algolia when a post has added, updated or deleted

## Config

Add in wp-config.php :

```
define('ALGOLIA_APP_ID', 'XXX');
define('ALGOLIA_APP_PUBLIC', "XXX");
define('ALGOLIA_APP_SECRET', "XXX");
```

## JS

The vars ```ALGOLIA_APP_ID```, ```ALGOLIA_APP_PUBLIC``` and ```ALGOLIA_APP_INDEX``` are shared across the page for use in javascript script.

Example of use :

```html




```

```js
import algoliasearch from 'algoliasearch/lite'
import instantsearch from 'instantsearch.js'
import { searchBox, hits, refinementList } from 'instantsearch.js/es/widgets'

const search = instantsearch({
indexName: ALGOLIA_APP_INDEX,
searchClient: algoliasearch(ALGOLIA_APP_ID, ALGOLIA_APP_PUBLIC),
searchFunction(helper) {
// Ensure we only trigger a search when there's a query
if (helper.state.query && helper.state.query !== '') {
document.getElementById('hits').removeAttribute('hidden')
helper.search()
} else {
document.getElementById('hits').setAttribute('hidden', true)
}
},
})

search.addWidgets([
searchBox({
container: '#searchbox',
}),
refinementList({
container: '#tag-list',
attribute: 'tags',
limit: 5,
showMore: true,
}),
hits({
container: '#hits',
templates: {
item: `



{{#helpers.highlight}}
{ "attribute": "title", "highlightedTagName": "mark" }
{{/helpers.highlight}}


{{#content}}

{{#helpers.highlight}}{ "attribute": "excerpt", "highlightedTagName": "mark" }{{/helpers.highlight}}


{{/content}}

`,
},
}),
])

search.start()

```

## Doc

- [https://www.algolia.com/doc/integration/wordpress/search/building-search-ui/?client=php](https://www.algolia.com/doc/integration/wordpress/search/building-search-ui/?client=php)