Views Hooks
Customize shortcodes, view configuration, facets, and search-page detection for CelerSearch views.
Shortcodes
celersearch_shortcodes
Filter the registered shortcode instances.
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;
});
| Parameter | Type | Description |
|---|---|---|
$shortcodes | AbstractShortcode | Array of shortcode instances |
celersearch_shortcode_atts
Filter parsed shortcode attributes before rendering.
add_filter('celersearch_shortcode_atts', function($atts, $tag) {
// Override limit for the search shortcode
if ($tag === 'celersearch') {
$atts['limit'] = 20;
}
return $atts;
}, 10, 2);
| Parameter | Type | Description |
|---|---|---|
$atts | array | Parsed shortcode attributes |
$tag | string | The 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.
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;
});
| Parameter | Type | Description |
|---|---|---|
$config | array | The view configuration |
Available config keys:
| Key | Type | Default | Description |
|---|---|---|---|
index_id | int | 0 | The index ID to search |
limit | int | 12 | Results per page |
placeholder | string | 'Search...' | Input placeholder text |
class | string | '' | CSS class for the container |
show_facets | bool | true | Whether to show facet filters |
highlight | bool | true | Enable result highlighting |
debounce | int | 300 | Debounce delay in ms |
min_chars | int | 2 | Minimum characters before search |
mode | string | 'live' | Search mode: 'live' or 'submit' |
initial_query | string | '' | Pre-filled search query |
initial_display | string | 'search_only' | Initial display: 'search_only' or 'browse' |
facet_groups_mode | string | 'all' | Facet groups: 'all', 'selected', or 'none' |
facet_groups | array | [] | Selected facet groups |
celersearch_view_search_js_config
Filter the JavaScript configuration passed to the search view frontend.
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);
| Parameter | Type | Description |
|---|---|---|
$config | array | The JavaScript configuration |
$view | SearchView | The view instance |
Config keys:
| Key | Type | Description |
|---|---|---|
instanceId | string | Unique view instance ID |
indexId | int | The index ID |
limit | int | Results per page |
placeholder | string | Input placeholder |
showFacets | bool | Whether facets are shown |
highlight | bool | Highlighting enabled |
debounce | int | Debounce delay in ms |
minChars | int | Min chars before search |
mode | string | Search mode |
initialQuery | string | Pre-filled query |
initialDisplay | string | Initial display mode |
facetLabels | array | Facet key => label mapping |
facetGroupsMode | string | Facet groups mode |
facetGroups | array | Selected facet groups |
Facets
celersearch_view_facet_labels
Filter the facet key-to-label mapping used in search views.
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);
| Parameter | Type | Description |
|---|---|---|
$labels | array | Facet key => display label mapping |
$view | SearchView | The view instance |
Default labels:
| Key | Label |
|---|---|
taxonomies.category | Category |
taxonomies.post_tag | Tags |
taxonomies.product_cat | Category |
taxonomies.product_tag | Tags |
in_stock | Availability |
ratings.average_rating | Rating |
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.
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);
| Parameter | Type | Description |
|---|---|---|
$facet_attributes | array | List of facet attribute names |
$index | BaseIndex | The 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.
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);
| Parameter | Type | Description |
|---|---|---|
$params | array | The search parameters |
$query | string | The search query string |
$index | BaseIndex | The index being searched |
Parameters structure:
[
'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.
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);
| Parameter | Type | Description |
|---|---|---|
$has | bool | Current detection result (always false when the filter runs) |
$page | WP_Post | The page being checked |