gpt4 book ai didi

Wordpress 使用 slug 获取分类名称

转载 作者:行者123 更新时间:2023-12-02 23:24:18 25 4
gpt4 key购买 nike

如何获得仅包含分类法别名的分类法 ID 或名称?

我想我正在寻找与 get_term_by() 等效的东西,但用于分类法。

编辑:我必须指定我正在尝试获取 WooCommerce 产品属性的税 ID。

谢谢

最佳答案

WordPress 确实提供了从其 slug 中获取分类信息的功能。

$taxonomy_details = get_taxonomy( $slug );

这会将分类详细信息作为对象返回,其中包括分类的各种标签。例如,这是调用标准类别分类法时返回的对象,例如get_taxonomy('类别');

stdClass Object
(
[labels] => stdClass Object
(
[name] => Categories
[singular_name] => Category
[search_items] => Search Categories
[popular_items] =>
[all_items] => All Categories
[parent_item] => Parent Category
[parent_item_colon] => Parent Category:
[edit_item] => Edit Category
[view_item] => View Category
[update_item] => Update Category
[add_new_item] => Add New Category
[new_item_name] => New Category Name
[separate_items_with_commas] =>
[add_or_remove_items] =>
[choose_from_most_used] =>
[not_found] => No categories found.
[menu_name] => Categories
[name_admin_bar] => category
)

[description] =>
[public] => 1
[hierarchical] => 1
[show_ui] => 1
[show_in_menu] => 1
[show_in_nav_menus] => 1
[show_tagcloud] => 1
[show_in_quick_edit] => 1
[show_admin_column] => 1
[meta_box_cb] => post_categories_meta_box
[rewrite] => Array
(
[hierarchical] => 1
[slug] => category
[with_front] => 1
[ep_mask] => 512
)

[query_var] => category_name
[update_count_callback] =>
[_builtin] => 1
[cap] => stdClass Object
(
[manage_terms] => manage_categories
[edit_terms] => manage_categories
[delete_terms] => manage_categories
[assign_terms] => edit_posts
)

[name] => category
[object_type] => Array
(
[0] => post
)

[label] => Categories
)

来源:https://codex.wordpress.org/Function_Reference/get_taxonomy

关于Wordpress 使用 slug 获取分类名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12548353/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com