Walk the whole guest roster from another add-on
For an add-on that needs every guest, not one by id or one episode’s: AI Search indexes the roster so a visitor finds a guest who is booked but on no episode yet, and backfills its index by walking it. Never query the benecaster_guest posts yourself.
benecaster_guest_manager_get_guests() ( array $args = [] ) returns [ 'guests' => list<array>, 'total' => int ]:
$args:page(from 1; default 1) andper_page(1 to 100; default 50; a larger number is cut to 100).guests: one page of published guests, A–Z by name. Each entry has exactly the keys benecaster_guest_manager_get_guest() returns (id,name,title,organization,website,photo_url,profile_url,bio,edit_url; see Read one guest by id from another add-on), and any key added there later. Never the guest’s email.total: the number of published guests. A page past the last is empty, with the sametotal.- Not gated by show. Guests are the site’s, so a guest linked to no episode, or only to episodes on a show where Guest Manager is off, is listed. When you draw a guest on an episode, check that episode’s show yourself with benecaster_addon_is_active()
( 'benecaster-addon-guest-manager', $show_id ). - Each entry passes
get_guest()‘s filter, benecaster_guest_manager_guest. A guest it hides is left out of its page without changingtotal, so a page may hold fewer thanper_page: keep paging until you have asked fortotalguests’ worth of pages, not until a page is short or empty. [ 'guests' => [], 'total' => 0 ]while Guest Manager is off on every show. Values are raw text: escape on output (esc_html(),esc_url()).- It is defined on every request while Guest Manager is active; guard calls with
function_exists()for Guest Manager not being installed.
To keep an index current, hook benecaster_guest_manager_after_save_guest and benecaster_guest_manager_after_delete_guest rather than walking the roster again.
Code
<?php
// Backfill a search index with every guest, 100 at a time.
if ( function_exists( 'benecaster_guest_manager_get_guests' ) ) {
$page = 1;
do {
$result = benecaster_guest_manager_get_guests( [ 'page' => $page, 'per_page' => 100 ] );
foreach ( $result['guests'] as $guest ) {
my_addon_index_guest( $guest['id'], $guest['name'] . ' ' . $guest['organization'] . ' ' . $guest['bio'] );
}
$page++;
} while ( ( $page - 1 ) * 100 < $result['total'] );
}
Hooks Used
Need this built rather than just documented? See our services →