Skip to main content

benecaster_ai_search_results

Filter Premium ai-search

Filters one search’s results from the benecaster_ai_search box, after AI Search has decided what the visitor may see, just before they are returned by GET /wp-json/benecaster-ai-search/v1/search. Each result is { id, title, url, date, excerpt, locked, pinned, html? }: the show’s firing pinned results first (pinned: true), then the best matches, at most 10.

Each episode has already been checked for the visitor with benecaster_user_can_access_episode(). One they cannot open is left out of a hidden box, and in a locked box arrives as locked: true with only id, title, url and the lock card’s html (date and excerpt empty). excerpt is the episode’s description, never transcript text.

Anything you add is shown to the visitor as it is: never add an episode or text the visitor may not see.

Parameters

Name Type Default Description
$results array — List of `{ id, title, url, date, excerpt, locked, pinned, html? }`
$query string — The search, trimmed
$show_id int — The show searched

Returns: array

Example

// Leave out results that are pinned posts or pages rather than episodes.
add_filter( 'benecaster_ai_search_results', function ( array $results, string $query, int $show_id ): array {
    return array_values( array_filter( $results, fn( array $r ): bool => 'benecaster_episode' === get_post_type( $r['id'] ) ) );
}, 10, 3 );

Notes

Not called for a refused request (AI Search off for the show, a query outside 2 to 200 characters, or a visitor over the rate limit). It is called when the provider failed or the show reached its daily limit, with only the pinned results. Walkthrough: Read, change or log AI Search's search results.

Affects

  • [benecaster_ai_search] shortcode
  • GET benecaster-ai-search/v1/search

Need this built rather than just documented? See our services →