acf_ensure_perm_readable_post_status()ACF 6.8.7

Normalizes an args array so perm=readable actually applies inside WP_Query.

WP_Query ignores perm=readable when post_status='any' (Trac #52094). Callers that opt into perm=readable therefore need post_status This helper is idempotent and safe to call before and after the per-field acf/fields/<type>/query filters run — the post-filter call catches callbacks that reset post_status to 'any' while leaving perm untouched.

No Hooks.

Returns

Array. Args with post_status when perm=readable requires it.

Usage

acf_ensure_perm_readable_post_status( $args );
$args(array) (required)
WP_Query args.

Changelog

Since 6.8.7 Introduced.

acf_ensure_perm_readable_post_status() code ACF 6.8.8

function acf_ensure_perm_readable_post_status( $args ) {
	if ( ! isset( $args['perm'] ) || 'readable' !== $args['perm'] ) {
		return $args;
	}

	$status = isset( $args['post_status'] ) ? $args['post_status'] : '';
	$is_any = empty( $status )
		|| 'any' === $status
		|| ( is_array( $status ) && in_array( 'any', $status, true ) );

	if ( $is_any ) {
		$args['post_status'] = get_post_stati( array( 'exclude_from_search' => false ) );
	}

	return $args;
}