Skip to main content

Skip importing trailer episodes during feed sync

Free Beginner

Feed Sync re-scans the source feed and drafts anything whose GUID isn’t already on the show. When the old host keeps a permanent trailer at the top of the feed, that trailer is otherwise drafted on every sync. Return false from benecaster_feed_sync_should_import to skip items whose <itunes:episodeType> is trailer.

Return false and no draft is created, and nothing is logged — the item still counts in the run’s episodes_new but not in drafts_created, and it’s offered to the filter again on the next sync. Feed Sync only: the setup wizard’s one-time import runs no filters, so a trailer imported that way still arrives as a draft.

Code

<?php
add_filter(
    'benecaster_feed_sync_should_import',
    function ( bool $should_import, SimpleXMLElement $rss_item, int $show_id ): bool {
        if ( ! $should_import ) {
            return false;
        }

        $itunes = $rss_item->children( 'http://www.itunes.com/dtds/podcast-1.0.dtd' );
        $type   = strtolower( trim( (string) ( $itunes->episodeType ?? '' ) ) );

        return 'trailer' !== $type;
    },
    10,
    3
);

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →