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.

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-includes/post.php WP 5.2.4

<?php
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 );
}

Related Functions

From tag: Custom post type (post_type)

More from category: Custom Types

No comments
    Hello, !     Log In . Register