Skip to main content

benecaster_get_sole_show_id()

Utilities Free
benecaster_get_sole_show_id(): ?int

Returns the show ID on a single-show install, and nothing on a multi-show one. “Active” here means published and not archived.

It is the last step in how Benecaster’s shortcodes decide which show they are for, after an explicit show_id and the current show or episode page. For your own shortcodes and blocks, call benecaster_resolve_show_id(), which runs all three steps in that order, so they pick the same show the built-in ones would.

Return Value

Type: int|null

The post ID of the single active show, or null when there are zero active shows or two or more of them. Both cases answer null.

Example

$show_id = benecaster_get_sole_show_id();

if ( ! $show_id ) {
    return '<p>' . esc_html__( 'Please pass a show_id — this site has more than one show.', 'my-addon' ) . '</p>';
}

Notes

null is not an error, and it does not mean "no shows". Zero active shows and five active shows both answer null — the question it really answers is "can a show be inferred without being told?". The correct response to null is to require an explicit show_id, never to fall back to a guess such as the most recent show.

Safe to call before the plugin container has booted. It instantiates ShowRepository directly rather than resolving it, and turns any throwable into null, so it is usable from early hooks where a container lookup would fatal.

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