Hooks Reference

CelerSearch provides 115 hooks — 109 named filters and actions plus 6 dynamic hook families — for customizing every aspect of the search experience.

Overview

CelerSearch uses WordPress filters and actions extensively, allowing you to:

  • Customize indexed data - Add fields, modify content, filter items
  • Control search behavior - Modify queries, filter results, change ranking
  • Extend functionality - Add custom index types, observers, providers
  • Fine-tune sync - Control what syncs, when, and how

Hook Types

Filters

Filters let you modify data as it passes through CelerSearch:

PHP
add_filter('hook_name', function($value, $param1, $param2) {
    // Modify $value
    return $value;
}, 10, 3);

Actions

Actions let you execute code at specific points:

PHP
add_action('hook_name', function($param1, $param2) {
    // Do something
}, 10, 2);

Hook Categories

CategoryCountDescription
Indexing36Customize what and how content is indexed
Search15Control query interception, results, sorting, and pinning
Autocomplete21Customize instant search suggestions
Views8Customize shortcodes, view config, facets, and page detection
WooCommerce6Customize shop filters, sorting, and order search
Sync9Control real-time synchronization
Services17Customize search engine settings and AI embedders

Counts reflect the hooks documented in each category; dynamic per-type hook families (e.g. celersearch_searchable_post_{post_type}_records) count once.

Quick Examples

PHP
add_filter('celersearch_should_sync_post', function($should_sync, $post, $index) {
    // Don't index posts with exclude meta
    if (get_post_meta($post->ID, 'exclude_from_search', true)) {
        return false;
    }
    return $should_sync;
}, 10, 3);

Add Custom Field to Index

PHP
add_filter('celersearch_searchable_post_shared_attributes', function($attrs, $post) {
    // Add custom meta to all indexed posts
    $attrs['custom_field'] = get_post_meta($post->ID, 'my_field', true);
    return $attrs;
}, 10, 2);

Modify Search Results

PHP
add_filter('celersearch_search_results', function($results, $query, $index) {
    // Add extra data to each result
    foreach ($results['hits'] as &$hit) {
        $hit['views'] = get_post_meta($hit['post_id'], 'views', true);
    }
    return $results;
}, 10, 3);

Custom Sorting

PHP
add_filter('celersearch_search_params', function($params, $query, $index) {
    // Sort by custom field
    $params['sort'] = ['popularity:desc', 'created_at:desc'];
    return $params;
}, 10, 3);

Hook Naming Conventions

CelerSearch hooks follow consistent naming patterns:

PatternPurposeExample
celersearch_*General plugin hookscelersearch_should_sync_post
celersearch_searchable_*Index data customizationcelersearch_searchable_post_records
celersearch_*_settingsSettings customizationcelersearch_products_index_settings

Dynamic Hooks

Some hooks include dynamic parts based on content type:

PHP
// Generic hook for all post types
add_filter('celersearch_searchable_post_records', ...);

// Specific hook for pages only
add_filter('celersearch_searchable_post_page_records', ...);

// Specific hook for products
add_filter('celersearch_searchable_product_simple_records', ...);

Next Steps