Indexing Hooks
Customize what content is indexed and how it's structured.
Post Status Control
celersearch_indexable_post_statuses
Control which post statuses are indexable.
add_filter('celersearch_indexable_post_statuses', function($statuses, $post) {
// Add 'archived' status for custom post types
if ($post->post_type === 'document') {
$statuses[] = 'archived';
}
return $statuses;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$statuses | array | Default: ['publish', 'draft', 'pending', 'private', 'future'] |
$post | WP_Post | The post being checked |
Content Modification
celersearch_searchable_post_content
Modify post content before indexing.
add_filter('celersearch_searchable_post_content', function($content, $post) {
// Add ACF field content
$custom_content = get_field('additional_content', $post->ID);
if ($custom_content) {
$content .= ' ' . $custom_content;
}
return $content;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$content | string | Post content |
$post | WP_Post | The post object |
celersearch_searchable_product_content
Modify WooCommerce product content before indexing.
add_filter('celersearch_searchable_product_content', function($content, $post) {
// Add product specifications
$specs = get_post_meta($post->ID, 'specifications', true);
if ($specs) {
$content .= ' ' . $specs;
}
return $content;
}, 10, 2);
Record Customization
celersearch_searchable_post_records
Customize the complete searchable records for posts.
add_filter('celersearch_searchable_post_records', function($records, $post) {
// Add custom data to all records
foreach ($records as $record) {
$data = $record->get_indexable_data();
$data['reading_time'] = calculate_reading_time($post->post_content);
// Note: You'll need to create a new record with modified data
}
return $records;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$records | array | Array of IIndexableObject instances |
$post | WP_Post | The post object |
celersearch_searchable_post_{post_type}_records
Customize records for a specific post type.
// Only affects 'page' post type
add_filter('celersearch_searchable_post_page_records', function($records, $post) {
// Page-specific customization
return $records;
}, 10, 2);
celersearch_searchable_product_records
Customize WooCommerce product records.
add_filter('celersearch_searchable_product_records', function($records, $post) {
// Add product-specific data
return $records;
}, 10, 2);
celersearch_searchable_product_{post_type}_records
Customize product records for a specific post type. Runs after the generic celersearch_searchable_product_records filter.
// Only affects the 'product' post type
add_filter('celersearch_searchable_product_product_records', function($records, $post) {
// Product-specific customization
return $records;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$records | array | Array of IIndexableObject instances |
$post | WP_Post | The post object |
celersearch_searchable_order_records
Customize WooCommerce order records.
add_filter('celersearch_searchable_order_records', function($records, $order) {
// Add order-specific data
return $records;
}, 10, 2);
Attribute Customization
celersearch_searchable_post_shared_attributes
Add or modify attributes for all posts.
add_filter('celersearch_searchable_post_shared_attributes', function($attrs, $post) {
// Add custom fields
$attrs['views'] = (int) get_post_meta($post->ID, 'views', true);
$attrs['rating'] = (float) get_post_meta($post->ID, 'rating', true);
// Add computed fields
$attrs['has_video'] = has_shortcode($post->post_content, 'video');
return $attrs;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$attrs | array | All indexed attributes |
$post | WP_Post | The post object |
Using Meta Box?
Meta Box fields — including those stored in Custom Database Tables — index through this same hook;
you just read the value with rwmb_meta() instead of get_post_meta(). See the dedicated, tested
recipe in Integrations → Meta Box.
celersearch_searchable_post_{post_type}_shared_attributes
Customize attributes for a specific post type.
add_filter('celersearch_searchable_post_product_shared_attributes', function($attrs, $post) {
// Product-specific attributes
$attrs['brand'] = get_post_meta($post->ID, 'brand', true);
return $attrs;
}, 10, 2);
celersearch_searchable_product_shared_attributes
Customize WooCommerce product attributes.
add_filter('celersearch_searchable_product_shared_attributes', function($attrs, $post) {
$product = wc_get_product($post);
// Add custom product data
$attrs['is_bestseller'] = get_post_meta($post->ID, 'bestseller', true);
$attrs['warranty'] = get_post_meta($post->ID, 'warranty_months', true);
return $attrs;
}, 10, 2);
celersearch_searchable_product_{post_type}_shared_attributes
Customize product attributes for a specific post type. Runs after the generic celersearch_searchable_product_shared_attributes filter.
add_filter('celersearch_searchable_product_product_shared_attributes', function($attrs, $post) {
$attrs['brand'] = get_post_meta($post->ID, 'brand', true);
return $attrs;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$attrs | array | All indexed attributes |
$post | WP_Post | The post object |
celersearch_searchable_order_attributes
Customize WooCommerce order attributes.
add_filter('celersearch_searchable_order_attributes', function($attrs, $order) {
// Add custom order data
$attrs['sales_rep'] = $order->get_meta('assigned_sales_rep');
return $attrs;
}, 10, 2);
celersearch_filterable_attribute_labels
Customize the labels displayed for filterable attributes in the admin UI.
add_filter('celersearch_filterable_attribute_labels', function($labels) {
// Add custom attribute label
$labels['taxonomies.genre'] = 'Genre';
// Rename an existing label
$labels['taxonomies.category'] = 'Topic';
return $labels;
});
| Parameter | Type | Description |
|---|---|---|
$labels | array | Attribute key => display label mapping |
Default labels include taxonomy names and WooCommerce product attributes (pa_*). This is used in the admin settings interface for configuring filterable attributes.
Index Settings
celersearch_posts_index_settings
Customize Posts index settings.
add_filter('celersearch_posts_index_settings', function($settings, $index) {
return $settings
->searchable_attributes([
'title',
'content',
'excerpt',
'custom_field', // Add custom field
])
->filterable_attributes([
'taxonomies.category.slug',
'author.display_name',
'status',
'views', // Add custom filter
])
->sortable_attributes([
'created_at',
'views', // Add custom sort
'rating',
]);
}, 10, 2);
celersearch_products_index_settings
Customize Products index settings.
add_filter('celersearch_products_index_settings', function($settings, $index) {
return $settings
->sortable_attributes([
'price',
'sale_price',
'popularity',
'rating',
]);
}, 10, 2);
celersearch_orders_index_settings
Customize Orders index settings.
add_filter('celersearch_orders_index_settings', function($settings, $index) {
return $settings
->filterable_attributes([
'status',
'customer.email',
'sales_rep',
]);
}, 10, 2);
Admin Attribute Whitelists
These filters control which attributes the admin UI offers when configuring an index's searchable, filterable, and sortable attributes. Each entry is an array with name (the attribute key), label (display label), and optional group (renders as an <optgroup> section in the picker).
If you add custom attributes to records (e.g. via celersearch_searchable_post_shared_attributes), register them here too so admins can select them in the UI.
celersearch_posts_available_searchable_attributes
Filter the searchable-attribute whitelist for the Posts index.
add_filter('celersearch_posts_available_searchable_attributes', function($attributes, $index) {
$attributes[] = [
'name' => 'subtitle',
'label' => 'Subtitle',
'group' => 'Content',
];
return $attributes;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$attributes | array | Entries of ['name' => string, 'label' => string, 'group' => ?string] |
$index | PostsIndex | The index instance |
celersearch_posts_available_filterable_attributes
Filter the filterable-attribute whitelist for the Posts index. Same signature as above ($attributes, $index).
add_filter('celersearch_posts_available_filterable_attributes', function($attributes, $index) {
$attributes[] = ['name' => 'views', 'label' => 'View count', 'group' => 'Custom'];
return $attributes;
}, 10, 2);
celersearch_posts_available_sortable_attributes
Filter the sortable-attribute whitelist for the Posts index. Same signature as above. Only expose scalar (non-array, non-object) fields — Meilisearch rejects sorts on arrays and objects.
add_filter('celersearch_posts_available_sortable_attributes', function($attributes, $index) {
$attributes[] = ['name' => 'views', 'label' => 'View count', 'group' => 'Custom'];
return $attributes;
}, 10, 2);
celersearch_products_available_searchable_attributes
Filter the searchable-attribute whitelist for the WooCommerce Products index.
add_filter('celersearch_products_available_searchable_attributes', function($attributes, $index) {
$attributes[] = ['name' => 'brand', 'label' => 'Brand', 'group' => 'Custom'];
return $attributes;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$attributes | array | Entries of ['name' => string, 'label' => string, 'group' => ?string] |
$index | ProductsIndex | The index instance |
celersearch_products_available_filterable_attributes
Filter the filterable-attribute whitelist for the Products index. Same signature as above ($attributes, $index).
add_filter('celersearch_products_available_filterable_attributes', function($attributes, $index) {
$attributes[] = ['name' => 'warranty_months', 'label' => 'Warranty (months)', 'group' => 'Custom'];
return $attributes;
}, 10, 2);
celersearch_products_available_sortable_attributes
Filter the sortable-attribute whitelist for the Products index. Same signature as above. Scalar fields only.
add_filter('celersearch_products_available_sortable_attributes', function($attributes, $index) {
$attributes[] = ['name' => 'total_sales', 'label' => 'Total sales', 'group' => 'Custom'];
return $attributes;
}, 10, 2);
Batch Processing
celersearch_indexable_items_batch_size
Set the default batch size for all indices.
add_filter('celersearch_indexable_items_batch_size', function($size) {
return 50; // Filter default: 15
});
Which batch size is used depends on how the rebuild runs:
- WP-CLI (
wp celersearch reindex <id>) uses this filter's value —15unless you change it here or pass--batch=<n>, which overrides the filter for that run. - Admin dashboard rebuilds use the batch size from Settings (default
100, clamped to10–500on save). That value is applied by temporarily overriding this filter during the rebuild, so a callback you add here does not affect dashboard rebuilds.
celersearch_{index_slug}_indexable_items_batch_size
Set batch size for a specific index.
add_filter('celersearch_products_indexable_items_batch_size', function($size) {
return 25; // Products are heavier, use smaller batches
});
Product Variations
celersearch_product_variations
Customize variable product variations data.
add_filter('celersearch_product_variations', function($variations, $product) {
// Add variation-specific data
foreach ($variations as &$var) {
$var['custom_attr'] = get_post_meta($var['id'], 'custom', true);
}
return $variations;
}, 10, 2);
Images
celersearch_post_images_sizes
Control which image sizes are indexed.
add_filter('celersearch_post_images_sizes', function($sizes) {
// Only index these sizes
return ['thumbnail', 'medium', 'large'];
});
celersearch_get_post_images
Modify the final images array.
add_filter('celersearch_get_post_images', function($images, $post_id) {
// Add gallery images
$gallery = get_post_meta($post_id, 'gallery_images', true);
if ($gallery) {
foreach ($gallery as $image_id) {
$images[] = wp_get_attachment_image_src($image_id, 'large')[0];
}
}
return $images;
}, 10, 2);
Content Processing
celersearch_strip_patterns
Customize regex patterns for stripping content noise.
add_filter('celersearch_strip_patterns', function($patterns) {
// Add pattern to strip custom shortcode
$patterns[] = '/\[my_shortcode[^\]]*\]/';
return $patterns;
});
celersearch_get_post_object_id
Customize object ID format for split records.
add_filter('celersearch_get_post_object_id', function($id, $post_id, $index) {
// Use custom ID format
return 'post_' . $post_id . '_chunk_' . $index;
}, 10, 3);
Extensibility
celersearch_searchable_post_types
Filter the post types considered searchable when building the index manager.
add_filter('celersearch_searchable_post_types', function($post_types) {
// Add a custom post type
$post_types['event'] = 'event';
// Remove attachments
unset($post_types['attachment']);
return $post_types;
});
| Parameter | Type | Description |
|---|---|---|
$post_types | array | Associative array of post type names (from get_post_types with exclude_from_search => false) |
celersearch_supported_indices
Register custom index types.
add_filter('celersearch_supported_indices', function($indices) {
$indices[] = [
'name' => 'Events',
'type' => 'events',
'model' => MyPlugin\Indices\EventsIndex::class,
'fields' => [
[
'label' => 'Event Types',
'name' => 'event_types',
'type' => 'dropdown',
'options' => fn() => [...],
'multiple' => true,
],
],
];
return $indices;
});
Supported field types: text, textarea, dropdown (set 'multiple' => true for a multi-select), and checkbox.
Admin Index Browser
celersearch_index_browse_list_fields
Filter which document fields are fetched for the list view of the admin index Browser (the debugging tool that pages through documents in an index). Only these summary fields are retrieved for performance — the full document is fetched on demand when a row is opened.
add_filter('celersearch_index_browse_list_fields', function($fields, $index) {
// Show the price column for product indices
$fields[] = 'price';
return $fields;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$fields | string | Fields to retrieve. Default: ['id', 'object_id', 'post_id', 'post_title', 'title', 'sku', 'images'] |
$index | BaseIndex | The index being browsed |
Actions
celersearch_rebuilt_items
Fires after an index rebuild completes.
add_action('celersearch_rebuilt_items', function($index_slug) {
// Clear caches, send notification, etc.
wp_cache_delete('search_stats', 'celersearch');
// Log completion
error_log("Index {$index_slug} rebuilt at " . date('Y-m-d H:i:s'));
});
celersearch_before_get_candidate_objects
Fires before converting a candidate to indexable objects.
add_action('celersearch_before_get_candidate_objects', function($item) {
// Pre-processing, caching, etc.
});
celersearch_after_get_candidate_objects
Fires after converting a candidate to indexable objects.
add_action('celersearch_after_get_candidate_objects', function($item) {
// Post-processing, cleanup, etc.
});