Skip to main content

benecaster_get_show_tiers()

Access Tier Free
benecaster_get_show_tiers( int $show_id ): array

Returns a show’s tiers — slug and display name — for building a tier picker in a block, a widget or a settings screen. It answers for every kind of show: one using Benecaster’s built-in memberships and one connected to an external membership plugin alike, so you do not need to work out which is in use.

It gives the same answer as the GET /editor/shows/{id}/tiers REST route, because the two share one implementation.

Parameters

Name Type Default Required Description
show_id int — Yes The show (post) ID.

Return Value

Type: array

A list of [ 'slug' => string, 'name' => string ] arrays, already in the show's tier order. Empty for an unknown show, a show with no tiers, or an id of 0 or less — never an error.

Example

foreach ( benecaster_get_show_tiers( $show_id ) as $rank => $tier ) {
    // $rank (0, 1, 2 …) IS the ordering. Do not sort by anything else.
    printf(
        '<option value="%s">%s</option>',
        esc_attr( $tier['slug'] ),
        esc_html( $tier['name'] )
    );
}

Notes

Rank tiers by their position in the list, never by a number fetched elsewhere. The list is already in the show's tier order. The stored tier_order value is 0 for every tier created in the Memberships admin, so comparing those values treats every tier as equal.

Slug and name only, deliberately. No prices, no subscriber counts and no "is this the free tier" flag. For a price, use [benecaster_tier_price]; for who holds a tier, use benecaster_get_user_tier_for_show().

An empty list is a normal answer. Render an empty state ("This show has no tiers yet") rather than treating it as a failure.

To tell which of two tiers ranks higher, call benecaster_compare_tiers() rather than comparing positions yourself. The list is lowest first: position 0 is the lowest tier.

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