benecaster_ai_search_after_search
Fires after a search from the benecaster_ai_search box, with the results the visitor is about to receive, after benecaster_ai_search_results. The place to log searches. Not fired for a refused request.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$query |
string |
— | The search, trimmed |
$show_id |
int |
— | The show searched |
$results |
array |
— | The filtered results, each `{ id, title, url, date, excerpt, locked, pinned, html? }` |
Example
// Count zero-result searches per show, to see what listeners look for and do not find.
add_action( 'benecaster_ai_search_after_search', function ( string $query, int $show_id, array $results ): void {
if ( [] === $results ) {
$counts = (array) get_option( 'my_ai_search_misses', [] );
$counts[ $show_id ] = ( $counts[ $show_id ] ?? 0 ) + 1;
update_option( 'my_ai_search_misses', $counts, false );
}
}, 10, 3 );
Notes
The query text is what a visitor typed: treat anything you store as personal data. Walkthrough: Read, change or log AI Search's search results.
Affects
- GET benecaster-ai-search/v1/search
Need this built rather than just documented? See our services →