benecaster_search_results
Filters the full episode search result set after all results are prepared and individual excerpts have passed through [benecaster_search_result_excerpt](/hooks/benecaster_search_result_excerpt/), but before the REST response is assembled. Use to reorder, annotate, or remove results.
This is a Free filter. It fires regardless of whether results came from the core SQL query or a [benecaster_search_pre_results](/hooks/benecaster_search_pre_results/) short-circuit, making it a reliable post-processing point regardless of the search backend in use. The `$data` array has the shape `{ results: array, total: int, pages: int }`.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$data |
array |
— | Result set: {results: array, total: int, pages: int} |
$q |
string |
— | Search term |
$show_id |
int |
— | Show post ID |
$tiers |
string[] |
— | Accessible tier slugs |
Returns:
array
Examples
Promote premium tier results to top
add_filter( 'benecaster_search_results', function( $data, $q, $show_id, $tiers ) {
// Move results from the 'premium' tier to the top for authenticated users.
if ( in_array( 'premium', $tiers, true ) ) {
usort( $data['results'], fn( $a, $b ) => ( 'premium' === $b['tier_slug'] ) - ( 'premium' === $a['tier_slug'] ) );
}
return $data;
}, 10, 4 );
Boost featured-tagged episodes to top
add_filter( 'benecaster_search_results', function( array $data, string $q, int $show_id, array $tiers ): array {
usort( $data['results'], function( $a, $b ) {
$a_featured = has_tag( 'featured', $a['episode_id'] ) ? 0 : 1;
$b_featured = has_tag( 'featured', $b['episode_id'] ) ? 0 : 1;
return $a_featured <=> $b_featured;
} );
return $data;
}, 10, 4 );
Affects
- GET /benecaster/v1/search REST endpoint
- [benecaster_search] shortcode