Autocomplete Hooks

Customize the instant search autocomplete functionality.

Behavior Settings

celersearch_autocomplete_debounce

Control delay before autocomplete triggers.

PHP
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.

PHP
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.

PHP
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.

PHP
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.

PHP
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.

PHP
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.

PHP
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.

PHP
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.

PHP
add_filter('celersearch_woocommerce_orders_input_selector', function($selector) {
    // Use a custom selector for your admin theme
    return '#my-orders-search-input';
});
ParameterTypeDescription
$selectorstringCSS 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.

PHP
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.

PHP
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.

PHP
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.

PHP
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);
ParameterTypeDescription
$should_attachboolWhether to attach (default: true)
$search_areaWooCommerceOrdersSearchAreaThe 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.

PHP
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);
ParameterTypeDescription
$paramsarraySearch parameters
$querystringSearch query string
$indexBaseIndexThe index being searched
$contextstringSearch context identifier

celersearch_autocomplete_statuses

Control which statuses appear in autocomplete.

PHP
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.

PHP
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);
ParameterTypeDescription
$hitarrayFormatted hit data
$raw_hitarrayRaw search engine hit
$postWP_PostThe WordPress post

Default hit structure:

PHP
[
    '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.

PHP
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.

PHP
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.

PHP
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.

PHP
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.

PHP
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;
});