register_{$taxonomy}_taxonomy_args
云策文档标注
概述
register_{$taxonomy}_taxonomy_args 是一个动态过滤器,用于在注册特定分类法时修改其参数。它允许开发者在分类法注册过程中自定义参数,如标签、可见性、REST API 集成等。
关键要点
- 过滤器名称是动态的,基于分类法键(如 register_category_taxonomy_args 或 register_post_tag_taxonomy_args)。
- 参数 $args 是一个数组,包含分类法的注册参数,如 labels、public、hierarchical、show_in_rest 等。
- 可用于调整分类法的 UI 显示、权限、重写规则、默认术语等高级设置。
- 通过 apply_filters 调用,传递 $args、分类法名称和对象类型数组。
代码示例
$args = apply_filters( "register_{$taxonomy}_taxonomy_args", $args, $this->name, (array) $object_type );注意事项
- 参数 $args 的结构与 register_taxonomy() 函数一致,需参考其文档以确保正确性。
- 动态部分 $taxonomy 必须替换为实际分类法键,以正确应用过滤器。
- 某些参数(如 _builtin)仅供内部使用,修改时需谨慎。
原文内容
Filters the arguments for registering a specific taxonomy.
Description
The dynamic portion of the filter name, $taxonomy, refers to the taxonomy key.
Possible hook names include:
register_category_taxonomy_argsregister_post_tag_taxonomy_args
Parameters
$argsarray- Array of arguments for registering a taxonomy.
See the register_taxonomy() function for accepted arguments.More Arguments from register_taxonomy( … $args )
Array or query string of arguments for registering a taxonomy.
labelsstring[]An array of labels for this taxonomy. By default, Tag labels are used for non-hierarchical taxonomies, and Category labels are used for hierarchical taxonomies. See accepted values in get_taxonomy_labels() .descriptionstringA short descriptive summary of what the taxonomy is for.publicboolWhether a taxonomy is intended for use publicly either via the admin interface or by front-end users. The default settings of$publicly_queryable,$show_ui, and$show_in_nav_menusare inherited from$public.publicly_queryableboolWhether the taxonomy is publicly queryable.
If not set, the default is inherited from$publichierarchicalboolWhether the taxonomy is hierarchical. Default false.show_uiboolWhether to generate and allow a UI for managing terms in this taxonomy in the admin. If not set, the default is inherited from$public(default true).show_in_menuboolWhether to show the taxonomy in the admin menu. If true, the taxonomy is shown as a submenu of the object type menu. If false, no menu is shown.
$show_uimust be true. If not set, default is inherited from$show_ui(default true).show_in_nav_menusboolMakes this taxonomy available for selection in navigation menus. If not set, the default is inherited from$public(default true).show_in_restboolWhether to include the taxonomy in the REST API. Set this to true for the taxonomy to be available in the block editor.rest_basestringTo change the base url of REST API route. Default is $taxonomy.rest_namespacestringTo change the namespace URL of REST API route. Default is wp/v2.rest_controller_classstringREST API Controller class name. Default is ‘WP_REST_Terms_Controller‘.show_tagcloudboolWhether to list the taxonomy in the Tag Cloud Widget controls. If not set, the default is inherited from$show_ui(default true).show_in_quick_editboolWhether to show the taxonomy in the quick/bulk edit panel. It not set, the default is inherited from$show_ui(default true).show_admin_columnboolWhether to display a column for the taxonomy on its post type listing screens. Default false.meta_box_cbbool|callableProvide a callback function for the meta box display. If not set, post_categories_meta_box() is used for hierarchical taxonomies, and post_tags_meta_box() is used for non-hierarchical. If false, no meta box is shown.meta_box_sanitize_cbcallableCallback function for sanitizing taxonomy data saved from a meta box. If no callback is defined, an appropriate one is determined based on the value of$meta_box_cb.capabilitiesstring[]Array of capabilities for this taxonomy.manage_termsstringDefault'manage_categories'.edit_termsstringDefault'manage_categories'.delete_termsstringDefault'manage_categories'.assign_termsstringDefault'edit_posts'.
rewritebool|arrayTriggers the handling of rewrites for this taxonomy. Default true, using $taxonomy as slug. To prevent rewrite, set to false. To specify rewrite rules, an array can be passed with any of these keys:slugstringCustomize the permastruct slug. Default$taxonomykey.with_frontboolShould the permastruct be prepended with WP_Rewrite::$front. Default true.hierarchicalboolEither hierarchical rewrite tag or not. Default false.ep_maskintAssign an endpoint mask. DefaultEP_NONE.
query_varstring|boolSets the query var key for this taxonomy. Default$taxonomykey. If false, a taxonomy cannot be loaded at?{query_var}={term_slug}. If a string, the query?{query_var}={term_slug}will be valid.update_count_callbackcallableWorks much like a hook, in that it will be called when the count is updated. Default _update_post_term_count() for taxonomies attached to post types, which confirms that the objects are published before counting them. Default _update_generic_term_count() for taxonomies attached to other object types, such as users.default_termstring|arrayDefault term to be used for the taxonomy.namestringName of default term.slugstringSlug for default term.descriptionstringDescription for default term.
sortboolWhether terms in this taxonomy should be sorted in the order they are provided towp_set_object_terms(). Default null which equates to false.argsarrayArray of arguments to automatically use insidewp_get_object_terms()for this taxonomy._builtinboolThis taxonomy is a “built-in” taxonomy. INTERNAL USE ONLY! Default false.
$taxonomystringTaxonomy key.$object_typestring[]Array of names of object types for the taxonomy.Source
$args = apply_filters( "register_{$taxonomy}_taxonomy_args", $args, $this->name, (array) $object_type );Changelog
Version Description 6.0.0 Introduced.
User Contributed Notes
You must log in before being able to contribute a note or feedback.