Skip to main content

benecaster_feed_episodes

Filter Free Since v1.0.0

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) and has already been capped by benecaster_feed_episode_limit at query time — episodes excluded at that earlier stage cannot be recovered here. Injected items must match the episode object shape expected by the feed compiler.

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 );

Limit free tier to 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

The episode array has already been capped by benecaster_feed_episode_limit before this filter runs — episodes excluded at the query stage cannot be recovered here. This is a Free filter — it fires regardless of license status.