Skip to content

Action Hooks

Michael Beckwith edited this page Oct 24, 2023 · 4 revisions

The available actions and how to use them.

Introduction

Actions are a way to execute code at a given point in time throughout the lifecyle of your WordPress website.

Action Example

Let's say we want to log every post indexing task.

<?php

function mb_log_posts_index_updated( $post ) {
    $log = print_r( $post->to_array(), true );
    file_put_contents( '../mb_logs.txt', $log, FILE_APPEND );
}

add_action( 'algolia_posts_index_post_updated', 'mb_log_post_index_updated' );

Note that an action does not need to return anything.

In this example, an array representation of the post that has been re-indexed would be logged.

Actions Reference

Here is the list of all available Actions.

Action Name Params
algolia_re_indexed_items string $index_id
algolia_de_indexed_items string $index_id
algolia_autocomplete_scripts none
algolia_instantsearch_scripts none
algolia_before_get_records mixed $item
algolia_after_get_records mixed $item
algolia_posts_index_post_updated WP_Post $post, array $records
algolia_posts_index_post_{$post_type}_updated WP_Post $post, array $records
algolia_searchable_posts_index_post_updated WP_Post $post, array $records
algolia_searchable_posts_index_post_{$post_type}_updated WP_Post $post, array $records
algolia_instantsearch_after_hit none
algolia_autocomplete_after_hit none