The What
Syntax
get_post_types( array|string $args = array(), string $output = 'names', string $operator = 'and' );
Description
This construct (function) gets all the registered post types and returns them as an array of names or objects. The post types are stored in the global variable $wp_post_types
. You specify whether you want to receive the list back with the names or the post type objects.
Keep in mind that when you call this function, it is fetching all the current registered post types.
Parameters
args
- Array or string of arguments to specify what you want to receive back from the request. Some of the arguments include:
_builtin
– boolean. Set totrue
to include the built-in post types; else, only the custom post types are returned.public
– boolean. Set totrue
if you want only public post typespublicly_queryable
– booleanexclude_from_search
– booleanshow_ui
– booleancapability_type
hierarchical
menu_position
menu_icon
permalink_epmask
rewrite
query_var
Refer to the list of arguments available when registering the post type.
output
- (Optional) Specify if you want the post type objects, i.e.
objects
, returned to you. The default isnames
, meaning you will receive an array of post type names. operator
- (Optional) The operator specifies whether the arguments are all of them (
and
) or any of them (or
). The default isand
.
Return Values
Returns an array of post type names or objects.
Hey... hey you... yes you!... Having a good time? Learning new things? Good!
More coming soon…keep checking back.