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.


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


get_post_types( $args, $output, $operator );
An array of key => value arguments to match against the post type objects.
Default: empty array
The type of output to return. Accepts post type 'names' or 'objects'.
Default: 'names'
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'


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


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