benecaster_feed_episodes
Filters the array of episode objects included in a compiled feed tier before XML serialization. Use to add, remove, reorder, or replace episodes programmatically — for example, to inject a static trailer episode at the top of every feed, exclude episodes from a specific season, or serve a reduced episode set on the public tier.
This filter fires once per tier per feed compilation. The array arrives in publication date order (newest first). Injected items must match the episode object shape expected by the feed compiler.
Removing an episode here takes it out of the feed and nothing else. Website playback follows the episode’s availability dates, so a listener whose tier has a date for it can still play it on your site. To take an episode away from a tier, clear that tier’s date. See Setting Tier Availability.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$episodes |
array |
— | Array of episode objects to be included in the compiled feed |
$show_id |
int |
— | ID of the show |
$tier_slug |
string |
— | Tier slug for this feed compilation pass |
Returns:
array
Examples
Pin static trailer episode at top of feed
add_filter( 'benecaster_feed_episodes', function( $episodes, $show_id, $tier_slug ) {
// Pin a static trailer episode at the top of every feed.
$trailer_id = (int) get_post_meta( $show_id, '_benecaster_pinned_trailer_id', true );
if ( $trailer_id ) {
$trailer = get_post( $trailer_id );
if ( $trailer ) {
array_unshift( $episodes, $trailer );
}
}
return $episodes;
}, 10, 3 );
Trim the free tier's feed to its 5 most recent episodes
add_filter( 'benecaster_feed_episodes', function ( array $episodes, int $show_id, string $tier_slug ): array {
if ( 'free' === $tier_slug ) {
return array_slice( $episodes, 0, 5 );
}
return $episodes;
}, 10, 3 );
Exclude episodes flagged with a custom field
add_filter( 'benecaster_feed_episodes', function ( array $episodes, int $show_id, string $tier_slug ): array {
return array_filter( $episodes, function ( $episode ) {
return ! get_post_meta( $episode->ID, '_exclude_from_feed', true );
} );
}, 10, 3 );
Notes
With pagination on (benecaster_feed_episode_limit returning a positive number), a listener on a single tier's feed gets one call per page, and the array holds that page's episodes only. Trimming it does not remove the later pages. For a listener whose feed merges two or more tiers, buy-ups or grants, the array holds each slug's full list, and pages are cut after the merge.
Need this built rather than just documented? See our services →