get_post_types

The timeline below displays how wordpress function get_post_types has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * Gets a list of all registered post type objects.
 *
 * @since 2.9.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type() for accepted arguments.
 *
 * @param array|string $args     Optional. An array of key => value arguments to match against
 *                               the post type objects. Default empty array.
 * @param string       $output   Optional. The type of output to return. Either 'names'
 *                               or 'objects'. Default 'names'.
 * @param string       $operator Optional. 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'.
 * @return string[]|WP_Post_Type[] An array of post type names or objects.
 */
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);
}

WordPress Version: 6.1

/**
 * Gets a list of all registered post type objects.
 *
 * @since 2.9.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type() for accepted arguments.
 *
 * @param array|string $args     Optional. An array of key => value arguments to match against
 *                               the post type objects. Default empty array.
 * @param string       $output   Optional. The type of output to return. Accepts post type 'names'
 *                               or 'objects'. Default 'names'.
 * @param string       $operator Optional. 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'.
 * @return string[]|WP_Post_Type[] An array of post type names or objects.
 */
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);
}

WordPress Version: 5.5

/**
 * Get a list of all registered post type objects.
 *
 * @since 2.9.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type() for accepted arguments.
 *
 * @param array|string $args     Optional. An array of key => value arguments to match against
 *                               the post type objects. Default empty array.
 * @param string       $output   Optional. The type of output to return. Accepts post type 'names'
 *                               or 'objects'. Default 'names'.
 * @param string       $operator Optional. 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'.
 * @return string[]|WP_Post_Type[] An array of post type names or objects.
 */
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);
}

WordPress Version: 5.1

/**
 * Get a list of all registered post type objects.
 *
 * @since 2.9.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type() for accepted arguments.
 *
 * @param array|string $args     Optional. An array of key => value arguments to match against
 *                               the post type objects. Default empty array.
 * @param string       $output   Optional. The type of output to return. Accepts post type 'names'
 *                               or 'objects'. Default 'names'.
 * @param string       $operator Optional. 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'.
 * @return string[]|WP_Post_Type[] An array of post type names or objects.
 */
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);
}

WordPress Version: 4.5

/**
 * Get a list of all registered post type objects.
 *
 * @since 2.9.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type() for accepted arguments.
 *
 * @param array|string $args     Optional. An array of key => value arguments to match against
 *                               the post type objects. Default empty array.
 * @param string       $output   Optional. The type of output to return. Accepts post type 'names'
 *                               or 'objects'. Default 'names'.
 * @param string       $operator Optional. 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'.
 * @return array A list of post type names or objects.
 */
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);
}

WordPress Version: 4.1

/**
 * Get a list of all registered post type objects.
 *
 * @since 2.9.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type() for accepted arguments.
 *
 * @param array|string $args     Optional. An array of key => value arguments to match against
 *                               the post type objects. Default empty array.
 * @param string       $output   Optional. The type of output to return. Accepts post type 'names'
 *                               or 'objects'. Default 'names'.
 * @param string       $operator Optional. The logical operation to perform. 'or' means only one
 *                               element from the array needs to match; 'and' means all elements
 *                               must match. Accepts 'or' or 'and'. Default 'and'.
 * @return array A list of post type names or objects.
 */
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);
}

WordPress Version: 4.0

/**
 * Get a list of all registered post type objects.
 *
 * @since 2.9.0
 *
 * @global array $wp_post_types List of post types.
 *
 * @see register_post_type()
 *
 * @param array|string $args     Optional. An array of key => value arguments to match against
 *                               the post type objects. Default empty array.
 * @param string       $output   Optional. The type of output to return. Accepts post type 'names'
 *                               or 'objects'. Default 'names'.
 * @param string       $operator Optaionl. The logical operation to perform. 'or' means only one
 *                               element from the array needs to match; 'and' means all elements
 *                               must match. Default 'and'.
 * @return array A list of post type names or objects.
 */
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);
}

WordPress Version: 3.9

/**
 * Get a list of all registered post type objects.
 *
 * @since 2.9.0
 * @uses $wp_post_types
 * @see register_post_type
 *
 * @param array|string $args An array of key => value arguments to match against the post type objects.
 * @param string $output The type of output to return, either post type 'names' or 'objects'. 'names' is the default.
 * @param string $operator The logical operation to perform. 'or' means only one element
 *  from the array needs to match; 'and' means all elements must match. The default is 'and'.
 * @return array A list of post type names or objects
 */
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);
}

WordPress Version: 3.7

/**
 * Get a list of all registered post type objects.
 *
 * @package WordPress
 * @subpackage Post
 * @since 2.9.0
 * @uses $wp_post_types
 * @see register_post_type
 *
 * @param array|string $args An array of key => value arguments to match against the post type objects.
 * @param string $output The type of output to return, either post type 'names' or 'objects'. 'names' is the default.
 * @param string $operator The logical operation to perform. 'or' means only one element
 *  from the array needs to match; 'and' means all elements must match. The default is 'and'.
 * @return array A list of post type names or objects
 */
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);
}