get_post_types( array|string $args = array(), string $output = 'names', string $operator = 'and' );
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.
- Array or string of arguments to specify what you want to receive back from the request. Some of the arguments include:
_builtin– boolean. Set to
trueto include the built-in post types; else, only the custom post types are returned.
public– boolean. Set to
trueif you want only public post types
Refer to the list of arguments available when registering the post type.
- (Optional) Specify if you want the post type objects, i.e.
objects, returned to you. The default is
names, meaning you will receive an array of post type names.
- (Optional) The operator specifies whether the arguments are all of them (
and) or any of them (
or). The default is
Returns an array of post type names or objects.
Hands off the keyboard. Web development starts by thinking first, then planning it out, and then coding it.
More coming soon…keep checking back.