WordPress at a glance

get_post_types() WP 1.0

Get a list of all registered post type objects.

1 time = 0.000001s = speed of light | 50000 times = 0.14s = very fast | PHP 7.1.11, WP 4.9.8

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.6

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 );

From tag: Custom post type (post_type)

More from category: Custom Types

No comments
    Log In