acf_get_post_types()ACF 5.0.0

Returns an array of post type names.

Hooks from the function

Returns

Array. A list of post type names.

Usage

acf_get_post_types( $args );
$args(array)
An array of key => value arguments to match against the post type objects.
Default: empty array

Changelog

Since 5.0.0 Introduced.

acf_get_post_types() code ACF 6.8.8

function acf_get_post_types( $args = array() ) {
	$post_types = array();

	// extract special arg
	$exclude   = acf_extract_var( $args, 'exclude', array() );
	$exclude[] = 'acf-field';
	$exclude[] = 'acf-field-group';
	$exclude[] = 'acf-post-type';
	$exclude[] = 'acf-taxonomy';
	$exclude[] = 'acf-ui-options-page';

	// Get post type objects.
	$objects = get_post_types( $args, 'objects' );

	foreach ( $objects as $i => $object ) {
		// Bail early if is exclude.
		if ( in_array( $i, $exclude ) ) {
			continue;
		}

		// Bail early if is builtin (WP) private post type
		// i.e. nav_menu_item, revision, customize_changeset, etc.
		if ( $object->_builtin && ! $object->public ) {
			continue;
		}

		$post_types[] = $i;
	}

	return apply_filters( 'acf/get_post_types', $post_types, $args );
}