Read an episode’s guests from another add-on
Show “Featuring…” lines, label transcript speakers or fill an email with an episode’s guests, through the one supported way to read them: never the benecaster_episode_guests table.
benecaster_guest_manager_get_episode_guests() returns the guests linked to an episode, in the episode’s order, each [ 'id' => int, 'name' => string, 'title' => string, 'organization' => string, 'website' => string, 'profile_url' => string ]:
idis the guest’s post id;namethe guest’s name;titletheir job or description (''when not set);organizationthe organization they are with (''when not set);websitethe guest’s own site,http/httpsonly, or''. To show title and organization as one line, join them as Guest Manager does: Founder, Acme Labs, or whichever is set.profile_urlis the guest’s public page:/guests/{slug}/, or/?benecaster_guest_page={slug}under plain permalinks,{slug}being the guest’s slug, which is kept when the guest is renamed.- The guest’s private email is never included.
- It returns
[]when the id is not an episode, when the episode has no guests, or when Guest Manager is not on for the episode’s own show. Only published guests are returned. - There is no access or status check on the episode: it answers for drafts too. If you show guests to a visitor, decide whether that visitor may see the episode.
- Values are raw text: escape on output (
esc_html(),esc_url()). - The function is defined on every request while Guest Manager is active, even when it is off on every show (it then returns
[]), sofunction_exists()only has to cover Guest Manager not being installed. - Keys may be added in later versions; none will be removed or change meaning.
benecaster_guest_manager_episode_guests filters the list above, ( array $guests, int $episode_id, int $show_id ): array. It runs only when Guest Manager is on for the episode’s show, so nothing can add guests to a switched-off show’s episode. A return that is not an array is ignored.
Code
<?php
// "Featuring Alice Smith and Bob Jones", each linked to their website when they have one.
$guests = function_exists( 'benecaster_guest_manager_get_episode_guests' )
? benecaster_guest_manager_get_episode_guests( $episode_id )
: [];
$names = array_map(
static fn( array $g ): string => '' !== $g['website']
? '<a href="' . esc_url( $g['website'] ) . '">' . esc_html( $g['name'] ) . '</a>'
: esc_html( $g['name'] ),
$guests
);
if ( [] !== $names ) {
echo esc_html__( 'Featuring', 'my-addon' ) . ' ' . wp_sprintf( '%l', $names );
}
Hooks Used
Need this built rather than just documented? See our services →