Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/wpperformance/wp-performance-algolia
- Owner: wpperformance
- Created: 2023-02-15T10:34:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-15T13:21:17.000Z (almost 2 years ago)
- Last Synced: 2024-10-30T11:46:36.580Z (about 2 months ago)
- Topics: algolia, algolia-instantsearch, wordpress, wordpress-plugin
- Language: PHP
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)