benecaster_guest_manager_get_guest_episodes()
benecaster_guest_manager_get_guest_episodes( int $guest_id ): array
The episodes a guest appears in, for an add-on that shows or indexes them, such as AI Search finding a guest by topic. It is the one supported way to read them: never query the benecaster_episode_guests table. See List a guest’s episodes from another add-on.
Parameters
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
guest_id |
int |
— | Yes | A benecaster_guest post id. |
Return Value
Type:
array
The guest's published episodes on shows where Guest Manager is on, newest first (publish date, then id), each [ 'episode_id' => int, 'show_id' => int ]. [] when the id is not a published guest (unknown, trashed, a draft, another post type), when the guest is on no such episode, and while Guest Manager is off on every show.
Example
$episodes = function_exists( 'benecaster_guest_manager_get_guest_episodes' )
? benecaster_guest_manager_get_guest_episodes( $guest_id )
: [];
foreach ( $episodes as $row ) {
if ( benecaster_user_can_access_episode( $row['episode_id'], get_current_user_id() ) ) {
echo esc_html( get_the_title( $row['episode_id'] ) );
}
}
Notes
Ids only; no access is decided. Before you show an episode to a visitor, ask
benecaster_user_can_access_episode()
( $episode_id, $user_id ) and draw a locked episode as locked. Never show an episode's content because a
guest appears in it.
It returns exactly the set the guest's public page lists before it decides access. An episode on a show where Guest Manager is switched off is left out, and comes back when it is switched on again: the link is kept.
To refresh a cache when a guest's episodes change, hook benecaster_guest_manager_after_change_episode_guests.
It is defined on every request while Guest Manager is active. Guard calls with function_exists(), since
Guest Manager may not be installed.
Need this built rather than just documented? See our services →