Views Hooks

Customize shortcodes, view configuration, facets, and search-page detection for CelerSearch views.

Shortcodes

celersearch_shortcodes

Filter the registered shortcode instances.

PHP
add_filter('celersearch_shortcodes', function($shortcodes) {
    // Add a custom shortcode
    $shortcodes[] = new MyCustomShortcode();

    // Remove the default search shortcode
    $shortcodes = array_filter($shortcodes, function($sc) {
        return !($sc instanceof \CelerSearch\Shortcodes\SearchShortcode);
    });

    return $shortcodes;
});
ParameterTypeDescription
$shortcodesAbstractShortcodeArray of shortcode instances

celersearch_shortcode_atts

Filter parsed shortcode attributes before rendering.

PHP
add_filter('celersearch_shortcode_atts', function($atts, $tag) {
    // Override limit for the search shortcode
    if ($tag === 'celersearch') {
        $atts['limit'] = 20;
    }

    return $atts;
}, 10, 2);
ParameterTypeDescription
$attsarrayParsed shortcode attributes
$tagstringThe shortcode tag name (the built-in search shortcode registers as celersearch)

View Configuration

celersearch_view_config

Filter the search view configuration after defaults are applied and types normalized.

PHP
add_filter('celersearch_view_config', function($config) {
    // Force live mode for all views
    $config['mode'] = 'live';

    // Set higher default limit
    $config['limit'] = 24;

    // Change debounce timing
    $config['debounce'] = 500;

    return $config;
});
ParameterTypeDescription
$configarrayThe view configuration

Available config keys:

KeyTypeDefaultDescription
index_idint0The index ID to search
limitint12Results per page
placeholderstring'Search...'Input placeholder text
classstring''CSS class for the container
show_facetsbooltrueWhether to show facet filters
highlightbooltrueEnable result highlighting
debounceint300Debounce delay in ms
min_charsint2Minimum characters before search
modestring'live'Search mode: 'live' or 'submit'
initial_querystring''Pre-filled search query
initial_displaystring'search_only'Initial display: 'search_only' or 'browse'
facet_groups_modestring'all'Facet groups: 'all', 'selected', or 'none'
facet_groupsarray[]Selected facet groups

celersearch_view_search_js_config

Filter the JavaScript configuration passed to the search view frontend.

PHP
add_filter('celersearch_view_search_js_config', function($config, $view) {
    // Add custom data for JS
    $config['customEndpoint'] = rest_url('my-plugin/v1/search');

    // Modify facet labels
    $config['facetLabels']['taxonomies.custom_tax'] = 'My Taxonomy';

    return $config;
}, 10, 2);
ParameterTypeDescription
$configarrayThe JavaScript configuration
$viewSearchViewThe view instance

Config keys:

KeyTypeDescription
instanceIdstringUnique view instance ID
indexIdintThe index ID
limitintResults per page
placeholderstringInput placeholder
showFacetsboolWhether facets are shown
highlightboolHighlighting enabled
debounceintDebounce delay in ms
minCharsintMin chars before search
modestringSearch mode
initialQuerystringPre-filled query
initialDisplaystringInitial display mode
facetLabelsarrayFacet key => label mapping
facetGroupsModestringFacet groups mode
facetGroupsarraySelected facet groups

Facets

celersearch_view_facet_labels

Filter the facet key-to-label mapping used in search views.

PHP
add_filter('celersearch_view_facet_labels', function($labels, $view) {
    // Add custom taxonomy label
    $labels['taxonomies.genre'] = 'Genre';

    // Rename existing label
    $labels['taxonomies.category'] = 'Topic';

    return $labels;
}, 10, 2);
ParameterTypeDescription
$labelsarrayFacet key => display label mapping
$viewSearchViewThe view instance

Default labels:

KeyLabel
taxonomies.categoryCategory
taxonomies.post_tagTags
taxonomies.product_catCategory
taxonomies.product_tagTags
in_stockAvailability
ratings.average_ratingRating

WooCommerce product attributes (pa_*) are automatically included with their registered labels.


celersearch_view_facet_attributes

Filter which attributes are used as facets in the search view REST API response.

PHP
add_filter('celersearch_view_facet_attributes', function($facet_attributes, $index) {
    // Add a custom facet
    $facet_attributes[] = 'in_stock';
    $facet_attributes[] = 'ratings.average_rating';

    return array_unique($facet_attributes);
}, 10, 2);
ParameterTypeDescription
$facet_attributesarrayList of facet attribute names
$indexBaseIndexThe index being searched

By default, only taxonomy-based filterable attributes are included as facets.


Search & Sorting

celersearch_view_search_params

Filter search parameters before execution in the search view REST API.

PHP
add_filter('celersearch_view_search_params', function($params, $query, $index) {
    // Add custom filter
    $params['filters'][] = [
        'field'    => 'visibility',
        'operator' => '=',
        'value'    => 'public',
    ];

    // Modify highlighting
    $params['highlighting']['fields'] = ['title', 'content', 'excerpt'];

    return $params;
}, 10, 3);
ParameterTypeDescription
$paramsarrayThe search parameters
$querystringThe search query string
$indexBaseIndexThe index being searched

Parameters structure:

PHP
[
    'limit'        => 12,
    'offset'       => 0,
    'facets'       => ['taxonomies.category', ...],
    'highlighting' => [
        'enabled'  => true,
        'fields'   => ['title', 'content'],
        'pre_tag'  => '<em class="celersearch-highlight">',
        'post_tag' => '</em>',
    ],
    'filters'      => [...],
    'sort'         => [...],
]

Sort options

Sort keys requested by a view (e.g. ?sort=date) are resolved to engine sort rules by the index itself. This is controlled by the celersearch_sort_options filter — it applies to all indices and every path that resolves a sort key (views, search area default sorts), so it is documented with the Search hooks.


Page Detection

celersearch_page_has_celersearch_content

Filter whether a page is detected as containing CelerSearch content — the [celersearch] shortcode, the celersearch/search block, or equivalent content stored by a page builder. The admin Settings page uses this to annotate the search-page dropdown with a status pill, so admins don't pick a page that would render an empty search screen.

Built-in detection covers post_content (shortcode + block) plus the meta keys used by Elementor (_elementor_data) and Bricks (_bricks_page_content_2). The filter only runs when built-in detection found nothing — return true to force-mark a page.

PHP
add_filter('celersearch_page_has_celersearch_content', function($has, $page) {
    // Support a page builder that stores its canvas in custom meta
    $builder_data = get_post_meta($page->ID, '_my_builder_data', true);
    if (is_string($builder_data) && stripos($builder_data, '[celersearch') !== false) {
        return true;
    }

    return $has;
}, 10, 2);
ParameterTypeDescription
$hasboolCurrent detection result (always false when the filter runs)
$pageWP_PostThe page being checked