Autocomplete Hooks
Customize the instant search autocomplete functionality.
Behavior Settings
celersearch_autocomplete_debounce
Control delay before autocomplete triggers.
add_filter('celersearch_autocomplete_debounce', function($delay, $search_area) {
// Faster for product search
if ($search_area->get_type() === 'woocommerce_product_search') {
return 150; // 150ms
}
return $delay; // Default: 300ms
}, 10, 2);
celersearch_autocomplete_min_chars
Set minimum characters before search starts.
add_filter('celersearch_autocomplete_min_chars', function($chars, $search_area) {
// More chars needed for short-word searches
return 3; // Default: 2
}, 10, 2);
celersearch_autocomplete_max_results
Control maximum results shown.
add_filter('celersearch_autocomplete_max_results', function($max, $search_area) {
// Show more results on desktop
return wp_is_mobile() ? 5 : 10; // Default: 5
}, 10, 2);
Search Area Configuration
celersearch_search_area_config
Customize the configuration passed to JavaScript.
add_filter('celersearch_search_area_config', function($config, $search_area) {
// Add custom template
$config['resultTemplate'] = 'custom-result';
// Add custom CSS class
$config['dropdownClass'] = 'my-autocomplete-dropdown';
// Add custom data
$config['customData'] = [
'tracking_id' => 'search_widget_1',
];
return $config;
}, 10, 2);
celersearch_autocomplete_js_config
Modify global JavaScript configuration.
add_filter('celersearch_autocomplete_js_config', function($config, $context) {
// Customize animation
$config['animation'] = 'slide';
// Add keyboard navigation
$config['keyboard'] = true;
return $config;
}, 10, 2);
Input Selectors
celersearch_public_search_input_selector
Customize which inputs get autocomplete on frontend.
add_filter('celersearch_public_search_input_selector', function($selector) {
// Add custom search input
return 'input[name="s"], .my-search-input';
});
Default: input[name="s"]:not(.no-autocomplete):not(#adminbar-search)
celersearch_woocommerce_product_search_input_selector
Customize WooCommerce product search input.
add_filter('celersearch_woocommerce_product_search_input_selector', function($selector) {
return '.woocommerce-product-search input[type="search"]';
});
celersearch_admin_post_type_input_selector
Customize admin search input selector.
add_filter('celersearch_admin_post_type_input_selector', function($selector, $post_type) {
// Custom selector for products
if ($post_type === 'product') {
return '#post-search-input, .product-search-field';
}
return $selector;
}, 10, 2);
celersearch_woocommerce_orders_input_selector
Customize the CSS selector for the WooCommerce orders search input in admin.
add_filter('celersearch_woocommerce_orders_input_selector', function($selector) {
// Use a custom selector for your admin theme
return '#my-orders-search-input';
});
| Parameter | Type | Description |
|---|---|---|
$selector | string | CSS selector. Default: '#orders-search-input-search-input' |
The default targets the HPOS orders page input (table ID orders-search-input with WP's -search-input suffix).
Attachment Control
celersearch_public_search_should_attach
Control if autocomplete attaches to frontend search.
add_filter('celersearch_public_search_should_attach', function($should_attach, $search_area) {
// Disable on specific pages
if (is_page('no-autocomplete')) {
return false;
}
return $should_attach;
}, 10, 2);
celersearch_woocommerce_product_search_should_attach
Control WooCommerce product search attachment.
add_filter('celersearch_woocommerce_product_search_should_attach', function($attach, $area) {
// Only on shop pages
return is_shop() || is_product_category();
}, 10, 2);
celersearch_admin_post_type_should_attach
Control admin search attachment.
add_filter('celersearch_admin_post_type_should_attach', function($attach, $area, $screen) {
// Only for specific post types
$allowed = ['post', 'page', 'product'];
return in_array($screen->post_type, $allowed, true);
}, 10, 3);
celersearch_woocommerce_orders_should_attach
Control whether autocomplete attaches to the WooCommerce orders search in admin.
add_filter('celersearch_woocommerce_orders_should_attach', function($should_attach, $search_area) {
// Only attach for shop managers
if (!current_user_can('manage_woocommerce')) {
return false;
}
return $should_attach;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$should_attach | bool | Whether to attach (default: true) |
$search_area | WooCommerceOrdersSearchArea | The search area instance |
This runs after verifying the current screen is the HPOS orders page or legacy orders list.
Search Parameters
celersearch_autocomplete_search_params
Modify autocomplete search parameters.
add_filter('celersearch_autocomplete_search_params', function($params, $query, $index, $context) {
// Add category filter
if (isset($_GET['product_cat'])) {
$params['filter'] = 'taxonomies.product_cat.slug = "' . sanitize_text_field($_GET['product_cat']) . '"';
}
// Boost in-stock products
$params['sort'] = ['in_stock:desc', '_rankingScore:desc'];
return $params;
}, 10, 4);
| Parameter | Type | Description |
|---|---|---|
$params | array | Search parameters |
$query | string | Search query string |
$index | BaseIndex | The index being searched |
$context | string | Search context identifier |
celersearch_autocomplete_statuses
Control which statuses appear in autocomplete.
add_filter('celersearch_autocomplete_statuses', function($statuses, $context) {
// Only published content in autocomplete
return ['publish'];
}, 10, 2);
Result Formatting
celersearch_autocomplete_hit
Customize individual autocomplete results.
add_filter('celersearch_autocomplete_hit', function($hit, $raw_hit, $post) {
// Add price for products
if ($post->post_type === 'product') {
$product = wc_get_product($post);
$hit['price'] = $product->get_price_html();
$hit['in_stock'] = $product->is_in_stock();
}
// Add custom thumbnail
$hit['thumbnail'] = get_the_post_thumbnail_url($post, 'thumbnail');
// Add read time for posts
$hit['read_time'] = calculate_read_time($post->post_content);
return $hit;
}, 10, 3);
| Parameter | Type | Description |
|---|---|---|
$hit | array | Formatted hit data |
$raw_hit | array | Raw search engine hit |
$post | WP_Post | The WordPress post |
Default hit structure:
[
'id' => 123,
'title' => 'Post Title',
'excerpt' => 'Short description...',
'url' => 'https://...',
'type' => 'post',
'thumbnail' => 'https://...',
]
Search Areas Registry
celersearch_active_autocomplete_areas
Filter active autocomplete search areas.
add_filter('celersearch_active_autocomplete_areas', function($areas) {
// Remove specific area
return array_filter($areas, function($area) {
return $area['type'] !== 'admin_media_search';
});
});
Custom Search Areas
celersearch_register_search_areas (Action)
Register custom search area types.
add_action('celersearch_register_search_areas', function() {
\CelerSearch\SearchAreas\SearchAreaRegistry::register(
'my_custom_search',
\MyPlugin\SearchAreas\CustomSearchArea::class
);
});
celersearch_area_types
Add custom search area types to the settings UI.
add_filter('celersearch_area_types', function($types) {
$types[] = [
'type' => 'my_custom_search',
'label' => __('My Custom Search', 'my-plugin'),
'description' => __('Search in custom content', 'my-plugin'),
'supports_autocomplete' => true,
'icon' => 'dashicons-search',
'category' => 'custom',
];
return $types;
});
Templates
celersearch_template_locations
Customize template search locations.
add_filter('celersearch_template_locations', function($locations, $template_name) {
// Add theme template location
array_unshift($locations, get_template_directory() . '/celersearch/');
return $locations;
}, 10, 2);
celersearch_js_templates
Customize JavaScript templates for rendering.
add_filter('celersearch_js_templates', function($templates) {
// Add custom result template
$templates['custom-result'] = '<div class="result">
<img src="{{ thumbnail }}">
<h4>{{ title }}</h4>
<span class="price">{{ price }}</span>
</div>';
return $templates;
});