On this page
get_post_types( array|string $args = array(), string $output = 'names', string $operator = 'and' ): string[]|WP_Post_Type[]
Gets a list of all registered post type objects.
Description
See also
- register_post_type() : for accepted arguments.
Parameters
$argsarray|string Optional-
An array of key => value arguments to match against the post type objects.
Default:
array() $outputstring Optional-
The type of output to return. Accepts post type
'names'or'objects'. Default'names'.Default:
'names' $operatorstring 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'.Default:
'and'
Return
string[]|WP_Post_Type[] An array of post type names or objects.
Source
File: wp-includes/post.php. View all references
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
| 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
| Used By | Description |
|---|---|
| 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_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. |
| export_wp() wp-admin/includes/export.php | Generates the WXR export file for download. |
| 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 | Remove 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 | Ajax handler for retrieving menu meta boxes. |
| wp_ajax_find_posts() wp-admin/includes/ajax-actions.php | Ajax handler for querying posts for the Find Posts modal. |
| 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 a 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. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_post_types