benecaster_search_query_args
Filters the structured query arguments passed to the episode search before the SQL query is built. Fires for both the search REST endpoint and the benecaster_search shortcode, in the search controller after tier resolution, giving you control over which show is searched, which tiers are accessible, how many results per page are returned, and the search term itself.
This is a Free filter. The $args array contains five keys: show_id, q, tiers, page, and per_page. Modified values are extracted individually before the search runs.
tiers is every slug the searcher holds on the show, not one tier: their tier slug, then any buy-up and standalone grant slugs, resolved the same way as their feed, so search finds what their feed carries — an episode gated to a buy-up or a grant included. It is ['public'] for an anonymous visitor, a logged-in user with no active feed on the show, and a lapsed member who owns nothing. The list you return here is the $tiers that benecaster_search_pre_results, benecaster_search_results and benecaster_search_supplemental_episode_ids receive.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$args |
array |
— | Query arguments: {show_id: int, q: string, tiers: string[], page: int, per_page: int}. `tiers` holds every tier, buy-up and grant slug the searcher holds, or `['public']`. |
$request |
WP_REST_Request |
— | The current REST request object |
Returns:
array
Examples
Cap results per page for nav widget
add_filter( 'benecaster_search_query_args', function( $args, $request ) {
// Cap results at 5 per page when called from the nav search widget.
if ( $request->get_header( 'X-Benecaster-Context' ) === 'nav-widget' ) {
$args['per_page'] = 5;
}
return $args;
}, 10, 2 );
Expand tier access for specific show
add_filter( 'benecaster_search_query_args', function( array $args, WP_REST_Request $request ): array {
if ( $args['show_id'] === 42 ) {
$args['tiers'] = [ 'public', 'supporter', 'founding' ];
}
return $args;
}, 10, 2 );
Affects
- GET /benecaster/v1/search REST endpoint
- benecaster_search shortcode
Need this built rather than just documented? See our services →