WordPress at a glance

get_post_types() WP 1.0

Get a list of all registered post type objects.

Notes:

  • Global. Array. $wp_post_types List of post types.
  • See: register_post_type() for accepted arguments.
✈ 1 time = 0.000001s = speed of light | 50000 times = 0.14s = very fast PHP 7.1.11, WP 4.9.8

No Hooks.

Return

Array. A list 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'

Code of get_post_types: wp-includes/post.php VER 4.9.8

<?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