Search a secondary data source and inject episode IDs into the Benecaster result set
Use when your add-on stores searchable content outside of wp_posts — transcripts, chapter titles, guest notes — and you want those episodes to appear in the standard [benecaster_search] results. Return the matching episode IDs; Benecaster merges them into the SQL so pagination totals stay correct. Apply your own visibility and tier gating before returning IDs — the filter result is trusted.
On querying your own tables. The example below queries an add-on’s own table, which is yours to change and safe to rely on. Querying Benecaster’s tables directly is a different matter: our schema is internal and can change in any release without notice, so a query written against it will break. Where a hook, shortcode, or public function can get you the data, use that instead — those we keep stable.
Code
<?php
add_filter(
'benecaster_search_supplemental_episode_ids',
function ( array $ids, string $term, int $show_id, array $tiers ): array {
global $wpdb;
$table = $wpdb->prefix . 'my_addon_transcripts';
if ( ! $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) ) {
return $ids;
}
$like = '%' . $wpdb->esc_like( $term ) . '%';
// Exclude visibility='hidden' to prevent unpublished content leaking via search.
$rows = $wpdb->get_col(
$wpdb->prepare(
"SELECT DISTINCT episode_id
FROM {$table}
WHERE show_id = %d
AND plain_text LIKE %s
AND visibility != 'hidden'",
$show_id,
$like
)
);
return array_merge( $ids, array_map( 'intval', $rows ) );
},
10, 4
);
Hooks Used
Need this built rather than just documented? See our services →