Skip to main content

benecaster_get_latest_episode_id()

Episode Free
benecaster_get_latest_episode_id( int $show_id ): ?int

Returns the ID of a show’s latest episode, for building “newest episode” surfaces in theme code and add-ons without writing the query yourself.

Resolution honours the same rules the [benecaster_latest_episode] shortcode uses, so a custom template and the shortcode agree about which episode is current.

Parameters

Name Type Default Required Description
$show_id int Yes WordPress post ID of the show.

Return Value

Type: int|null

The post ID of the show's most recent published episode, or null when the show has no published episodes — or when a filter has deliberately suppressed one.

Example

$episode_id = benecaster_get_latest_episode_id( $show_id );
if ( $episode_id ) {
    echo esc_html( get_the_title( $episode_id ) );
}

Hooks Fired

Notes

Always check for null before using the result. It is null when the show has no published episodes, and also when an operator has pinned or suppressed the latest episode through the benecaster_latest_episode_id filter — which is a supported configuration, not an error state.

The filter can also pin a specific episode as the perpetual latest, so the value is not guaranteed to be the most recently published one.

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