Skip to main content

benecaster_episode_nav_prev

Filter Free

Filters the WP_Post object for the previous episode in episode/navigation.php. Return null to suppress the previous link.

Return a WP_Post, or null when there is no previous episode. The value is not cast, so whatever is returned is used as-is.

Returning something that is not a WP_Post and not null — an ID, for instance — is not validated here and surfaces later as a property access on a non-object. Return get_post( $id ), not $id.

When this and benecaster_episode_nav_next both end up null, the whole navigation block is suppressed (the shortcode returns an empty string and the template returns). So a callback nulling one direction does not remove the nav; nulling both removes it entirely.

Parameters

Name Type Default Description
$post WP_Post|null Previous episode WP_Post object, or null if there is no previous episode
$episode_id int ID of the current episode
$show_id int ID of the show

Returns: WP_Post|null

Example

add_filter( 'benecaster_episode_nav_prev', function( $post, $episode_id, $show_id ) {
    // Suppress the previous link for the oldest episode in a season.
    if ( $post ) {
        $post_season    = get_post_meta( $post->ID, '_benecaster_season_number', true );
        $current_season = get_post_meta( $episode_id, '_benecaster_season_number', true );
        if ( $post_season !== $current_season ) {
            return null;
        }
    }
    return $post;
}, 10, 3 );

Affects

  • episode/navigation.php template part

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