List content only from the shows where your add-on is on
A page that spans shows, such as a public archive, a directory or a cross-show report, must leave out the shows where the podcaster switched your add-on off, or whose license does not include it. benecaster_addon_is_active_for_any_show() only answers yes or no, and looping benecaster_addon_is_active() over every show by hand is easy to get wrong. Ask benecaster_addon_active_show_ids() for the list instead.
Code
<?php
add_shortcode( 'my_addon_archive', static function (): string {
$show_ids = benecaster_addon_active_show_ids( 'benecaster-addon-my-addon' );
if ( [] === $show_ids ) {
return ''; // On for no show: render nothing.
}
$episodes = get_posts( [
'post_type' => 'benecaster_episode',
'post_status' => 'publish',
'post_parent__in' => $show_ids,
'posts_per_page' => 20,
] );
$items = array_map(
static fn( WP_Post $e ): string => '<li><a href="' . esc_url( get_permalink( $e ) ) . '">' . esc_html( get_the_title( $e ) ) . '</a></li>',
$episodes
);
return '<ul class="my-addon-archive">' . implode( '', $items ) . '</ul>';
} );
Need this built rather than just documented? See our services →