Skip to main content

List a guest’s episodes from another add-on

Premium Beginner Guest Manager

For an add-on that shows or indexes the episodes a guest appeared in: AI Search finds a guest by topic through their episodes. Never read the benecaster_episode_guests table.

benecaster_guest_manager_get_guest_episodes() ( int $guest_id ) returns list<[ 'episode_id' => int, 'show_id' => int ]>:

  • The guest’s published episodes on shows where Guest Manager is on, newest first (publish date, then id). It is exactly the set the guest’s public page lists before it decides access (see Restyle, extend or override a guest’s public page): both read the same query.
  • Ids only; no access is decided. Before you show one to a visitor, ask benecaster_user_can_access_episode() ( $episode_id, $user_id ) and draw a locked episode as locked, as the guest page does with Benecaster’s archive/episode-card.php. Never show an episode’s content because a guest appears in it.
  • [] 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.
  • 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.
  • It is defined on every request while Guest Manager is active; guard calls with function_exists() for Guest Manager not being installed.

To refresh a cache when a guest’s episodes change, hook benecaster_guest_manager_after_change_episode_guests.

Code

<?php
// A guest's episodes in a search result, each locked or not for the viewer.
$episodes = function_exists( 'benecaster_guest_manager_get_guest_episodes' )
    ? benecaster_guest_manager_get_guest_episodes( $guest_id )
    : [];
foreach ( $episodes as $row ) {
    $can_access = benecaster_user_can_access_episode( $row['episode_id'], get_current_user_id() );
    benecaster_get_template_part( 'archive/episode-card', [ 'episode_id' => $row['episode_id'], 'can_access' => $can_access ] );
}

View on GitHub →

Hooks Used

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