Skip to main content

benecaster_get_download_total()

Free
benecaster_get_download_total( int $show_id, array $args = [] ): int

Returns how many tracked downloads a show, or one of its episodes, had over a window. It is the same figure as the Downloads panel in Benecaster’s analytics, from the same calculation.

Read downloads through this, never from Benecaster’s tables. Benecaster keeps individual download records for about 30 days and then rolls older days up into daily totals, so a query on the individual records alone silently under-reports any range that reaches further back. This function reads both.

Parameters

Name Type Default Required Description
show_id int — Yes WordPress post ID of the show.
args array [] No Optional. episode_id — count one episode only; it must be an episode of $show_id, or the answer is 0. date_from — the start of the window; null, the default, means no lower bound. date_to — the end of the window; defaults to now. Dates are UTC and inclusive, as Y-m-d (the whole day) or Y-m-d H:i:s.

Return Value

Type: int

The number of tracked downloads in the window. 0 when there are none, when episode_id is not an episode of the show, or when a date is malformed.

Example

$last_year = benecaster_get_download_total( $show_id, [
    'date_from' => gmdate( 'Y-m-d', strtotime( '-1 year' ) ),
] );
printf( esc_html__( '%s tracked downloads in the last year', 'my-addon' ), esc_html( number_format_i18n( $last_year ) ) );

Notes

It is a floor, not the audience. Only downloads that pass through Benecaster's download tracking are counted: episodes with tracking on, since it was switched on. Label the figure "tracked".

A malformed date returns 0 and raises a _doing_it_wrong() notice, rather than widening the window to all time. Dates are UTC.

There is no capability check. For a breakdown by tier, app, day or episode, use benecaster_get_downloads_by(), which follows the same rules.

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