Algolia Connector
A WordPress plugin for Algolia search with multisite support
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/upstatement/algolia-connector-wp-plugin/archive/refs/heads/main.zipAlgolia Connector WordPress plugin
Hooks up a connection from WordPress to Algolia.
[!WARNING] Note that this plugin is in active development and may have missing features or bugs. It is intended primarily as a starting point for a WordPress to Algolia integration. Use with caution!
System Requirements
- PHP 8.2 or newer.
- WordPress version 6.6 or newer.
- Composer
Installation
- Download this plugin and add it to the
/wp-content/plugins/directory of your WordPress environment. - Install PHP dependencies by running
composer installin the plugin directory.
Usage
Once you have set up your Algolia application, retrieve your account credentials in the API Keys section of your Algolia account. This plugin provides a settings page that can be used to store these values, but it is recommended that you use environment variables (you can also save the values as constants). The following
| Value | Variable name |
|---|---|
| Application ID | ALGOLIA_APPLICATION_ID |
| Search API key | ALGOLIA_SEARCH_API_KEY |
| Admin API key | ALGOLIA_ADMIN_API_KEY |
| Index name | ALGOLIA_INDEX_NAME |
Configuring your theme
The plugin exposes a few hooks that allow you to customize what and how data gets sent to the Algolia index.
do_action( "algolia_indexable_post_types", array $post_types )
By default, no content types will be indexed. You can add which post types should be indexed by returning them from the algolia_indexable_post_types filter:
Parameters
-
$post_typesarrayThe list of post types that can be indexed.
Example
add_filter( 'algolia_indexable_post_types', function( $post_types ) {
$indexable_types = array( 'post', 'page', 'some_custom_type' );
return array_merge( $post_types, $indexable_types );
} );
do_action( "algolia_{$post->post_type}_to_record", array $record )
You can customize the Algolia record with the algolia_{$post->post_type}_to_record hook, replacing the dynamic portion with the post type handle.
Parameters
-
$recordarrayThe record object that will be saved to Algolia. By default, the record is saved with the following values:
distinct_keyA unique identifier for the post object within Algolia.post_idID of the post.titleTitle of the post.post_typeType of the post.urlA URL for the post, retrieved withget_permalink().bookA default boost setting.contentContent. This is usually one of the searchable fields.
// Modify the record for all Page posts.
add_filter( 'algolia_page_to_record', function ( $record ) {
// You can access the WP_Post object like this:
$_post = get_post( $record['post_id'] );
// Add other Page data, like post metadata, to the record.
$record['date'] = get_post_meta( $record['post_id'], 'some_meta_key', true );
return $record;
} );
WP CLI
This plugin comes with a few WP CLI commands that can be used to manage an index.
# Reindex everything.
wp algolia reindex
# Reindex just posts and pages.
wp algolia reindex --type=post,page
# Reindex a single post.
wp algolia reindex_single 123
# Delete all records in an index.
wp algolia clear
# Test the connection.
wp algolia test_connectionReleases
1 release.
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.