Developer Reference
Developer Reference
This page is for developers extending or customising the HawkSearch plugin. The same information is summarised on the plugin's HawkSearch → Developers page.
Don't edit the plugin's files
Updates replace the plugin's files. Make customisations with the filters on this page, in your theme's
functions.phpor a small custom plugin.
Where the Code Lives
| Part | Where |
|---|---|
| Rapid UI | Not bundled. Version 7.0.3 is loaded from the jsDelivr CDN, pinned so a new release never changes a live site by surprise: https://cdn.jsdelivr.net/npm/@bridgeline-digital/[email protected]/dist/hawksearch-handlebars-ui.min.js |
| Rapid UI settings | Printed in the page head as a HawkSearch.init() call, built in hawksearch/includes/class-search.php. On pages that only need a recommendation widget or tracking, it is printed in the footer. |
| Indexing | includes/class-items.php (what is sent per item) and includes/class-indexer.php (reindex, schedule, real-time updates). |
| Fields and facets | includes/class-fields.php and includes/class-facets.php (HawkSearch Dashboard API). |
| Tracking | includes/class-tracking.php (product views, add to cart and purchases). |
| Recommendations | includes/class-recommendations.php. |
Rapid UI is loaded on the results page; on every page once site search is on; and on any page with a recommendation widget or a tracked event (product views, cart, order confirmation).
Only the Client GUID and the public endpoints reach the browser. The API key is used only on the server.
Configuration Constants
Settings can be defined in wp-config.php, for example to keep the API key out of the database or to use different engines per environment. A constant overrides the value on the Settings page, and the field is shown as locked.
define( 'HAWKSEARCH_API_KEY', 'your-api-key' );
define( 'HAWKSEARCH_CLIENT_GUID', 'your-client-guid' );
define( 'HAWKSEARCH_ENGINE', 'yourengine' );
define( 'HAWKSEARCH_ENVIRONMENT', 'prod' ); // dev, test or prod
Shortcodes
| Shortcode | What it does |
|---|---|
[hawksearch_results] | Search results, facets, tabs, sorting and paging. Goes on the results page. |
[hawksearch_search_field] | A search box with autocomplete, anywhere. |
[hawksearch_recommendations widget="..."] | A recommendation widget. Optional item="123" sets the item; on a single product, post or page the current item is used automatically. |
Filters
Search and Rapid UI
| Filter | Arguments | Use |
|---|---|---|
hawksearch_rapid_ui_config | array $config | Change the HawkSearch.init() settings: field mappings, component templates, strings, styles. |
hawksearch_search_field_html | string $html, string $style | Change the search box markup, for example for Smart Search. |
hawksearch_rapid_ui_url | string $url | Load another Rapid UI version, or a copy on your own server. |
The default field mappings are:
| Rapid UI | HawkSearch field |
|---|---|
| title | title |
| url | url |
| imageUrl | image_url |
| description | excerpt, then content |
| price | regular_price |
| salePrice | sale_price |
| sku, brand, rating | sku, brand, rating |
| type | type (item for products, content otherwise) |
Indexing
| Filter | Arguments | Use |
|---|---|---|
hawksearch_post_types | array $types | Change which content types are indexed. |
hawksearch_excluded_ids | array $ids | Keep particular posts, pages or products out of HawkSearch. |
hawksearch_indexable | bool $indexable, WP_Post $post | Decide per item whether it is indexed. |
hawksearch_index_item | array $item, WP_Post $post | Change or add values before an item is sent. |
hawksearch_item_type | string $type, WP_Post $post | Set an item's type: item (shown as a product) or content. Useful for a custom product post type. |
hawksearch_tab_value | string $tab, WP_Post $post | Change the results tab an item appears under. |
hawksearch_detected_fields | array $fields, array $types | Change the fields found by Detect Fields. |
hawksearch_skip_meta_keys | array $keys | Custom field keys that Detect Fields should ignore. |
Items are sent as field name: array of values, for example:
{
"id": ["1600"],
"title": ["Women's Dree Jacket"],
"url": ["https://example.com/product/womens-dree-jacket/"],
"image_url": ["https://example.com/wp-content/uploads/dree-jacket.jpg"],
"type": ["item"],
"tab": ["Products"],
"price": [89],
"category": ["Jackets"],
"brand": ["Prana"]
}
Use Indexing → Preview an item to see exactly what is sent for any item.
Examples
Rename a Results Tab
add_filter( 'hawksearch_tab_value', function ( $tab, $post ) {
return 'post' === $post->post_type ? 'Blog Posts' : $tab;
}, 10, 2 );
Run a reindex afterwards, and update the facet's Default Item Type in the Workbench if you rename the Products tab.
Add a Value to Every Item
The field must exist in HawkSearch (create it in the Workbench, or add it as a custom field and sync it on the Field Configuration page).
add_filter( 'hawksearch_index_item', function ( $item, $post ) {
$item['region'] = array( get_post_meta( $post->ID, 'region', true ) ?: 'All' );
return $item;
}, 10, 2 );
Using Smart Search
Use the unified Smart Search box everywhere the plugin places a search box. Smart Search must be enabled for your engine first.
add_filter( 'hawksearch_search_field_html', function () {
return '<div class="hawksearch-search-box"><hawksearch-unified-search-field></hawksearch-unified-search-field></div>';
} );
For Smart Response, add <hawksearch-smart-response></hawksearch-smart-response> in a Custom HTML block above the results shortcode. See Available Enhancements.
Changing the Look of Results
Each Rapid UI component has a Handlebars template you can replace (Rapid UI Overrides). Copy the component's default markup from the component reference into a template tag on the page, change it, and point the component at it:
add_filter( 'hawksearch_rapid_ui_config', function ( $config ) {
$config['components']['search-results-item']['template'] = 'my-result-item';
return $config;
} );
add_action( 'wp_footer', function () {
echo '<template id="my-result-item">';
echo '<!-- your copy of the search-results-item markup -->';
echo '</template>';
} );
To hide a component, set its template to an empty string.
Adding Custom Styles
add_filter( 'hawksearch_rapid_ui_config', function ( $config ) {
$config['css']['customStyles'][] = '.search-results-list__item__title { font-weight: 700; }';
return $config;
} );
Rapid UI components use shadow DOM, so styles passed this way reach inside them; normal theme CSS styles only the page around them.
Tracking Events in the Browser
With verbose logging on (HawkSearch → Tracking), every event is written to the browser console, prefixed [HawkSearch tracking]. The plugin calls Rapid UI's tracking service, so all events share Rapid UI's visitor and visit IDs:
| Event | Rapid UI call |
|---|---|
| Product view | HawkSearch.services.tracking.trackPageLoad(1, productId) |
| Add to cart | trackAddToCart(productId, quantity, price, currency) |
| Purchase | trackOrder(orderNumber, items, subTotal, tax, total, currency) |
To track a custom event, wait for Rapid UI and use the same service:
addEventListener( 'hawksearch:initialized', function () {
HawkSearch.services.tracking.trackPageLoad( 5 ); // 5 = other page type
} );
See the Event Tracking API for event types.
Scheduled Tasks
| Hook | What it does |
|---|---|
hawksearch_scheduled_reindex | The scheduled full reindex (WP-Cron). |
hawksearch_index_tick | Runs reindex batches in the background. With WooCommerce, batches use Action Scheduler (group hawksearch). |
hawksearch_sync_items | Sends real-time updates to HawkSearch. |
With WP-CLI, wp cron event run hawksearch_scheduled_reindex starts the scheduled reindex immediately.
Stored Settings
The plugin stores its settings in WordPress options whose names start with hawksearch_, for example hawksearch_settings (connection), hawksearch_fields (Field Configuration), hawksearch_indexing, hawksearch_search, hawksearch_tracking and hawksearch_recommendations. Facets and recommendation widgets are stored in HawkSearch, not in WordPress.
Updated 1 day ago

