WordPress at Your Fingertips

get_post_types() WP 1.0

Get a list of all registered post type objects.

1 time — -0.00003 sec (speed of light) | 50000 times — 0.24 sec (very fast) | PHP 7.4.8, WP 5.6.2

No Hooks.

Return

String[]|WP_Post_Type[]. An array of post type names or objects.

Usage

get_post_types( $args, $output, $operator );
$args(array|string)
An array of key => value arguments to match against the post type objects.
Default: empty array
$output(string)
The type of output to return. Accepts post type 'names' or 'objects'.
Default: 'names'
$operator(string)
The logical operation to perform. 'or' means only one element from the array needs to match; 'and' means all elements must match; 'not' means no elements may match.
Default: 'and'

Notes

  • Global. Array. $wp_post_types List of post types.
  • See: register_post_type() for accepted arguments.

Changelog

Since 2.9.0 Introduced.

Code of get_post_types() WP 5.8.1

function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) {
	global $wp_post_types;

	$field = ( 'names' === $output ) ? 'name' : false;

	return wp_filter_object_list( $wp_post_types, $args, $operator, $field );
}

Custom post type (post_type)

Custom Types

No comments
    Log In