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:
add_filter('hook_name', function($value, $param1, $param2) {
// Modify $value
return $value;
}, 10, 3);
Actions
Actions let you execute code at specific points:
add_action('hook_name', function($param1, $param2) {
// Do something
}, 10, 2);
Hook Categories
| Category | Count | Description |
|---|---|---|
| Indexing | 36 | Customize what and how content is indexed |
| Search | 15 | Control query interception, results, sorting, and pinning |
| Autocomplete | 21 | Customize instant search suggestions |
| Views | 8 | Customize shortcodes, view config, facets, and page detection |
| WooCommerce | 6 | Customize shop filters, sorting, and order search |
| Sync | 9 | Control real-time synchronization |
| Services | 17 | Customize 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
Exclude Posts from Search
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
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
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
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:
| Pattern | Purpose | Example |
|---|---|---|
celersearch_* | General plugin hooks | celersearch_should_sync_post |
celersearch_searchable_* | Index data customization | celersearch_searchable_post_records |
celersearch_*_settings | Settings customization | celersearch_products_index_settings |
Dynamic Hooks
Some hooks include dynamic parts based on content type:
// 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
- Indexing hooks - Customize indexed data
- Search hooks - Control search behavior
- Autocomplete hooks - Customize suggestions
- Views hooks - Customize shortcodes, views, and facets
- WooCommerce hooks - Customize shop filters and order search
- Sync hooks - Control real-time sync
- Service hooks - Customize search engine settings