^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_object_taxonomies()用法示例

get_object_taxonomies( array|string|WP_Post $object,  string $output = 'names' )

Return 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.


描述

Example:

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

$taxonomies = get_object_taxonomies( 'post' );

This results in:

Array( 'category', 'post_tag' )

参数

$object

(array|string|WP_Post)
(Required)
Name of the type of taxonomy object, or an object (row from posts)

$output

(string)
(Optional)
The type of output to return in the array. Accepts either taxonomy ‘names’ or ‘objects’.

Default value: ‘names’


返回值

(array) The names of all taxonomy of $object_type.


源代码

File: wp-includes/taxonomy.php

function get_object_taxonomies( $object, $output = 'names' ) {
	global $wp_taxonomies;

	if ( is_object($object) ) {
		if ( $object->post_type == 'attachment' )
			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;
}

更新日志

Version 描述
2.3.0 Introduced.

相关函数

Uses

  • wp-includes/media.php:
    get_attachment_taxonomies()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::prepare_links()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::get_item_schema()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::get_collection_params()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::prepare_item_for_response()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::handle_terms()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::check_assign_terms_permission()
  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php:
    WP_REST_Taxonomies_Controller::get_items_permissions_check()
  • wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php:
    WP_REST_Taxonomies_Controller::get_items()
  • wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php:
    WP_REST_Post_Types_Controller::prepare_item_for_response()
  • wp-includes/class-wp-post-type.php:
    WP_Post_Type::unregister_taxonomies()
  • wp-includes/post.php:
    wp_queue_posts_for_term_meta_lazyload()
  • wp-admin/includes/export.php:
    wxr_post_taxonomy()
  • wp-admin/includes/template.php:
    get_inline_data()
  • wp-admin/includes/post.php:
    bulk_edit_posts()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::inline_edit()
  • wp-admin/includes/class-wp-posts-list-table.php:
    WP_Posts_List_Table::get_columns()
  • wp-includes/class-wp-query.php:
    WP_Query::get_posts()
  • wp-includes/taxonomy.php:
    update_object_term_cache()
  • wp-includes/taxonomy.php:
    get_the_taxonomies()
  • wp-includes/taxonomy.php:
    get_post_taxonomies()
  • wp-includes/taxonomy.php:
    is_object_in_taxonomy()
  • wp-includes/taxonomy.php:
    clean_object_term_cache()
  • wp-includes/nav-menu-template.php:
    _wp_menu_item_classes_by_context()
  • wp-includes/media.php:
    get_attachment_taxonomies()
  • wp-includes/post.php:
    _update_term_count_on_transition_post_status()
  • wp-includes/post.php:
    wp_delete_attachment()
  • wp-includes/post.php:
    wp_delete_post()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::_insert_post()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::_prepare_post()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::_prepare_post_type()
  • Show 26 more used by
    Hide more used by


  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Taxonomy names for post type

    
    <?php 
    	$taxonomy_names = get_object_taxonomies( 'post' );
    	print_r( $taxonomy_names);
    ?>
    

    will typically output:

    
    Array
    (
    	[0] => category
    	[1] => post_tag
    	[2] => post_format
    )
    
  2. Taxonomy objects for post type
    If the $output parameter is 'objects', taxonomy objects will be returned as described in get_taxonomies().

    
    <?php 
    	$taxonomy_objects = get_object_taxonomies( 'post', 'objects' );
    	print_r( $taxonomy_objects);
    ?>
    

    will output

    
    Array
    (
        [category] => stdClass Object
            (
                [hierarchical] => 1
                [update_count_callback] => 
                [rewrite] => 
                [query_var] => category_name
                [public] => 1
                [show_ui] => 1
                [show_tagcloud] => 1
                [_builtin] => 1
                [labels] => stdClass Object
                    (
                        ...
                    )
                ...
                [name] => category
                [label] => Categories
            )
        [post_tag] => stdClass Object
            (
                ...
            )
        [post_format] => stdClass Object
            (
                ....
            )
    )
    

    Taxonomy names for post object
    To get the taxonomies for the current post, the current post object can be passed instead of the post type.

    
    <?php 
    add_action('wp_head','wpdocs_output_current_post_taxonomies');
    
    /**
     * Output taxonomies for the current post
     */
    function wpdocs_output_current_post_taxonomies(){
    	global $post;
    
    	$taxonomy_names = get_object_taxonomies( $post );
    	print_r( $taxonomy_names );
    }
    ?>
    

    will output

    
    Array
    (
        [0] => category
        [1] => post_tag
        [2] => post_format
    )
    

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈