On this page
get_object_taxonomies( string|string[]|WP_Post $object, string $output = 'names' ): string[]|WP_Taxonomy[]
Returns the names or objects of the taxonomies which are registered for the requested object or object type, such as a post object or post type name.
Description
Example:
$taxonomies = get_object_taxonomies( 'post' );
This results in:
Array( 'category', 'post_tag' )
Parameters
$objectstring|string[]|WP_Post Required-
Name of the type of taxonomy object, or an object (row from posts)
$outputstring Optional-
The type of output to return in the array. Accepts either
'names'or'objects'. Default'names'.Default:
'names'
Return
string[]|WP_Taxonomy[] The names or objects of all taxonomies of $object_type.
Source
File: wp-includes/taxonomy.php. View all references
function get_object_taxonomies( $object, $output = 'names' ) {
global $wp_taxonomies;
if ( is_object( $object ) ) {
if ( 'attachment' === $object->post_type ) {
return get_attachment_taxonomies( $object, $output );
}
$object = $object->post_type;
}
$object = (array) $object;
$taxonomies = array();
foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) {
if ( array_intersect( $object, (array) $tax_obj->object_type ) ) {
if ( 'names' === $output ) {
$taxonomies[] = $tax_name;
} else {
$taxonomies[ $tax_name ] = $tax_obj;
}
}
}
return $taxonomies;
}
Related
Uses
| Uses | Description |
|---|---|
| get_attachment_taxonomies() wp-includes/media.php | Retrieves taxonomies attached to given the attachment. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Menu_Items_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Prepares a single post output for response. |
| WP_REST_Menu_Items_Controller::get_item_schema() wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php | Retrieves the term’s schema, conforming to JSON Schema. |
| WP_REST_Posts_Controller::prepare_tax_query() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares the ‘tax_query’ for a collection of posts. |
| WP_REST_Posts_Controller::prepare_taxonomy_limit_schema() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares the collection schema for including and excluding items by terms. |
| register_and_do_post_meta_boxes() wp-admin/includes/meta-boxes.php | Registers the default post meta boxes, and runs the |
| WP_REST_Posts_Controller::get_available_actions() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Gets the link relations available for the post and current user. |
| WP_REST_Posts_Controller::get_schema_links() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves Link Description Objects that should be added to the Schema for the posts collection. |
| WP_REST_Posts_Controller::prepare_links() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares links for the request. |
| WP_REST_Posts_Controller::get_item_schema() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves the post’s schema, conforming to JSON Schema. |
| WP_REST_Posts_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares a single post output for response. |
| WP_REST_Posts_Controller::handle_terms() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Updates the post’s terms from a REST request. |
| WP_REST_Posts_Controller::check_assign_terms_permission() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Checks whether current user can assign all terms sent with the current request. |
| WP_REST_Taxonomies_Controller::get_items_permissions_check() wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php | Checks whether a given request has permission to read taxonomies. |
| WP_REST_Taxonomies_Controller::get_items() wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php | Retrieves all public taxonomies. |
| WP_REST_Post_Types_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php | Prepares a post type object for serialization. |
| WP_Post_Type::unregister_taxonomies() wp-includes/class-wp-post-type.php | Removes the post type from all taxonomies. |
| wp_queue_posts_for_term_meta_lazyload() wp-includes/post.php | Queues posts for lazy-loading of term meta. |
| wxr_post_taxonomy() wp-admin/includes/export.php | Outputs list of taxonomy terms, in XML tag format, associated with a post. |
| get_inline_data() wp-admin/includes/template.php | Adds hidden fields with the data for use in the inline editor for posts and pages. |
| bulk_edit_posts() wp-admin/includes/post.php | Processes the post data for the bulk editing of posts. |
| WP_Posts_List_Table::inline_edit() wp-admin/includes/class-wp-posts-list-table.php | Outputs the hidden row displayed when inline editing |
| WP_Posts_List_Table::get_columns() wp-admin/includes/class-wp-posts-list-table.php | |
| WP_Query::get_posts() wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. |
| update_object_term_cache() wp-includes/taxonomy.php | Updates the cache for the given term object ID(s). |
| get_the_taxonomies() wp-includes/taxonomy.php | Retrieves all taxonomies associated with a post. |
| get_post_taxonomies() wp-includes/taxonomy.php | Retrieves all taxonomy names for the given post. |
| is_object_in_taxonomy() wp-includes/taxonomy.php | Determines if the given object type is associated with the given taxonomy. |
| clean_object_term_cache() wp-includes/taxonomy.php | Removes the taxonomy relationship to terms from the cache. |
| _wp_menu_item_classes_by_context() wp-includes/nav-menu-template.php | Adds the class property classes for the current context, if applicable. |
| get_attachment_taxonomies() wp-includes/media.php | Retrieves taxonomies attached to given the attachment. |
| _update_term_count_on_transition_post_status() wp-includes/post.php | Updates the custom taxonomies’ term counts when a post’s status is changed. |
| wp_delete_attachment() wp-includes/post.php | Trashes or deletes an attachment. |
| wp_publish_post() wp-includes/post.php | Publishes a post by transitioning the post status. |
| wp_insert_post() wp-includes/post.php | Inserts or update a post. |
| wp_delete_post() wp-includes/post.php | Trashes or deletes a post or page. |
| wp_xmlrpc_server::_insert_post() wp-includes/class-wp-xmlrpc-server.php | Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
| wp_xmlrpc_server::_prepare_post() wp-includes/class-wp-xmlrpc-server.php | Prepares post data for return in an XML-RPC object. |
| wp_xmlrpc_server::_prepare_post_type() wp-includes/class-wp-xmlrpc-server.php | Prepares post data for return in an XML-RPC object. |
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_object_taxonomies