Gets a list of all registered post type objects.
Description
See also
- register_post_type(): for accepted arguments.
Parameters
$args
array|stringoptional- An array of key => value arguments to match against the post type objects.
Default:
array()
$output
stringoptional- The type of output to return. Either
'names'
or'objects'
. Default'names'
.Default:
'names'
$operator
stringoptional- 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'
.Default:
'and'
Return
string[]|WP_Post_Type[] An array of post type names or objects.Source
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
Uses | Description |
---|---|
wp_filter_object_list()wp-includes/functions.php | Filters a list of objects, based on a set of key => value arguments. |
Used by | Description |
---|---|
WP_Query::generate_cache_key()wp-includes/class-wp-query.php | Generates cache key. |
get_template_hierarchy()wp-includes/block-template-utils.php | Gets the template hierarchy for the given template slug to be created. |
WP_REST_Block_Patterns_Controller::get_items_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php | Checks whether a given request has permission to read block patterns. |
WP_REST_Block_Pattern_Categories_Controller::get_items_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php | Checks whether a given request has permission to read block patterns. |
WP_REST_Menu_Items_Controller::check_has_read_only_access()wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Checks whether the current user has read permission for the endpoint. |
WP_REST_URL_Details_Controller::permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php | Checks whether a given request has permission to read remote URLs. |
WP_REST_Menus_Controller::check_has_read_only_access()wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php | Checks whether the current user has read permission for the endpoint. |
_build_block_template_result_from_post()wp-includes/block-template-utils.php | Builds a unified template object based a post Object. |
WP_REST_Templates_Controller::get_items_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php | Checks if a given request has access to read templates. |
WP_REST_Templates_Controller::get_item_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php | Checks if a given request has access to read a single template. |
WP_REST_Pattern_Directory_Controller::get_items_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php | Checks whether a given request has permission to view the local block pattern directory. |
WP_REST_Server::add_active_theme_link_to_index()wp-includes/rest-api/class-wp-rest-server.php | Adds a link to the active theme for users who have proper permissions. |
WP_REST_Themes_Controller::check_read_active_theme_permission()wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php | Checks if a theme can be read. |
do_all_trackbacks()wp-includes/comment.php | Performs all trackbacks. |
do_all_enclosures()wp-includes/comment.php | Performs all enclosures. |
do_all_pingbacks()wp-includes/comment.php | Performs all pingbacks. |
WP_REST_Block_Types_Controller::check_read_permission()wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php | Checks whether a given block type should be visible. |
WP_Sitemaps_Users::get_users_query_args()wp-includes/sitemaps/providers/class-wp-sitemaps-users.php | Returns the query args for retrieving users to list in the sitemap. |
WP_Sitemaps_Posts::get_object_subtypes()wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php | Returns the public post types, which excludes nav_items and similar types. |
WP_REST_Post_Search_Handler::__construct()wp-includes/rest-api/search/class-wp-rest-post-search-handler.php | Constructor. |
WP_Theme::get_post_templates()wp-includes/class-wp-theme.php | Returns the theme’s post templates. |
create_initial_rest_routes()wp-includes/rest-api.php | Registers default REST API routes. |
WP_REST_Users_Controller::get_collection_params()wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php | Retrieves the query params for collections. |
WP_REST_Users_Controller::get_items_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php | Permissions check for getting all users. |
WP_REST_Users_Controller::get_items()wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php | Retrieves all users. |
WP_REST_Users_Controller::get_item_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php | Checks if a given request has access to read a user. |
WP_REST_Post_Statuses_Controller::check_read_permission()wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Checks whether a given post status should be visible. |
WP_REST_Post_Statuses_Controller::get_items_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php | Checks whether a given request has permission to read post statuses. |
WP_REST_Post_Types_Controller::get_items_permissions_check()wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php | Checks whether a given request has permission to read types. |
WP_REST_Post_Types_Controller::get_items()wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php | Retrieves all public post types. |
get_post_embed_url()wp-includes/embed.php | Retrieves the URL to embed a specific post in an iframe. |
WP_Screen::render_view_mode()wp-admin/includes/class-wp-screen.php | Renders the list table view mode preferences. |
WP_Customize_Nav_Menus::search_available_items_query()wp-includes/class-wp-customize-nav-menus.php | Performs post queries for available-item searching. |
WP_Customize_Nav_Menus::available_item_types()wp-includes/class-wp-customize-nav-menus.php | Returns an array of all the available item types. |
set_screen_options()wp-admin/includes/misc.php | Saves option for number of rows when listing posts, pages, comments, etc. |
wp_delete_user()wp-admin/includes/user.php | Delete user and optionally reassign posts and links to another user. |
wp_edit_posts_query()wp-admin/includes/post.php | Runs the query to fetch the posts for listing on the edit posts page. |
wp_ajax_menu_get_metabox()wp-admin/includes/ajax-actions.php | Handles for retrieving menu meta boxes via AJAX. |
wp_ajax_find_posts()wp-admin/includes/ajax-actions.php | Handles querying posts for the Find Posts modal via AJAX. |
WP_Terms_List_Table::__construct()wp-admin/includes/class-wp-terms-list-table.php | Constructor. |
wp_nav_menu_post_type_meta_boxes()wp-admin/includes/nav-menu.php | Creates meta boxes for any post type menu item. |
WP::parse_request()wp-includes/class-wp.php | Parses the request to find the correct WordPress query. |
WP_Query::get_posts()wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. |
WP_Embed::cache_oembed()wp-includes/class-wp-embed.php | Triggers a caching of all oEmbed results. |
get_permalink()wp-includes/link-template.php | Retrieves the full permalink for the current post or post ID. |
wp_admin_bar_new_content_menu()wp-includes/admin-bar.php | Adds “Add New” menu. |
WP_User_Query::prepare_query()wp-includes/class-wp-user-query.php | Prepares the query variables. |
_get_last_post_time()wp-includes/post.php | Gets the timestamp of the last time any post was modified or published. |
get_pages()wp-includes/post.php | Retrieves an array of pages (or hierarchical post type items). |
_add_post_type_submenus()wp-includes/post.php | Adds submenus for post types. |
WP_Rewrite::generate_rewrite_rules()wp-includes/class-wp-rewrite.php | Generates rewrite rules from a permalink structure. |
url_to_postid()wp-includes/rewrite.php | Examines a URL and try to determine the post ID it represents. |
redirect_guess_404_permalink()wp-includes/canonical.php | Attempts to guess the correct URL for a 404 request based on query vars. |
wp_xmlrpc_server::wp_getPostTypes()wp-includes/class-wp-xmlrpc-server.php | Retrieves post types. |
_WP_Editors::wp_link_query()wp-includes/class-wp-editor.php | Performs post queries for internal linking. |
Changelog
Version | Description |
---|---|
2.9.0 | Introduced. |
Argument values for $args include:
Output a list of only custom post types which are public
By setting
'_builtin'
tofalse
, we exclude the WordPress built-in public post types (post
,page
,attachment
,revision
, andnav_menu_item
) and retrieve only registered custom public post types._builtin
option also ignores the following:custom_css
,customize_changeset
,oembed_cache
,user_request
,wp_block
,wp_template
.Retrieve a named post type as an object
This example uses the
'object'
output to retrieve the post type called ‘movies’ and display its name, singular name and menu icon (an URL):Get post types array with name => singular name
You can use this function in a select dropdown option where user can select a post type form existing post types.
Display the HTML dropdown list of Post Types.
Output a list of the names of all registered post types
Uses
'names'
as$output
argument value.Display the HTML dropdown list of Post Types, including custom post types
Remove specific post type
attachment
post type from the$post_types
variable; it does not actually unregister (“remove”) theattachment
post type.Default Usage
Retrieves the names (in an array) of all built-in and custom post types.