Detailed explanation of WORDPRESS built-in register_taxonomy function

One year ago (2023-11-09) Shallow singing
9 minutes
four hundred and twelve
zero

Common functions: register_taxonomy This function is unavoidable in the development of wordpress themes. It is used to create a custom taxonomy.

 <? php  /** *Create a custom category *@ param $taxonomy [The name of the taxonomy. This name should not contain Chinese, because it is not for users, but is similar to the role of ID] *@ param $post_type [Which article types are used for the taxonomy, such as post, page, attachment, revision, and nav_menu_item] *@ param $args [detailed below] */ register_taxonomy ($taxonomy, $post_type, $args);  ?>

Example of use

 $labels = array( 'name'=>__ ('filter tag ', THEME_LANGUAGE), 'singular_name '=>__ ('multiple filter label', THEME_LANGUAGE), 'search_items'=>__ ('Search tag ', THEME_LANGUAGE), 'all_items'=>__ ('All tags', THEME_LANGUAGE), 'menu_name '=>__ ('filter tag', THEME_LANGUAGE), 'edit_item'=>__ ('Edit tag ', THEME_LANGUAGE), 'update_item'=>__ ('Update label ', THEME_LANGUAGE), 'add_new_item'=>__ ('Add tag ', THEME_LANGUAGE), 'new_item_name'=>__ ('new tag value ', THEME_LANGUAGE), 'not_found'=>__ ('No label temporarily ', THEME_LANGUAGE), ); register_taxonomy ('attr', array('post'), array(   'hierarchical'          => false,   'labels'                => $labels,   'show_ui'               => true,   'show_in_rest'          => true,   'show_admin_column'     => true,   'query_var'             => true,   'publicly_queryable'    => true,     'public'                => false ));
Use the above code to add a filter label category to the article menu.
 WeChat screenshots_20221109112217

$args detailed parameters

  • Label: The name displayed to the user by the taxonomy, which can use Chinese and other characters
  • Labels: nouns displayed to users. This array is used to set the key text displayed to the user. If WordPress is not filled in, it will automatically set it for you (refer to the labels parameter below)
  • Public: whether to publish it. If it is published, the foreground archive page will be generated
  • Show_ui: Whether to display in the background side management menu
  • Show_in_nav_menus: Add a term to the menu page
  • Show_tagcloud: Whether the taxonomy displays the components of the tag cloud
  • Meta_box_cb: What is the form of the taxonomy selection section displayed in the article editor
  • Show_admin_column: whether to display on the data column of background article list
  • Hierarchical: displays the form of the taxonomy selection block in the article editor. If it is set to True, it is the classification form (multi choice box), and if it is set to False, it is the label form (text box and add button) [Note: whether the management interface of taxonomy is like "classification" or "label" depends on your hierarchical parameters]
  • Update_count_callback: the callback function when the taxonomy changes
  • Query_var: the keyword for querying the archive page. The default is the taxonomy name (ID). It's better to keep the default
  • Rewrite: pseudo static rule. If set to False, pseudo static will be disabled; You can also set some elements, such as "slug"
  • Capabilities: taxonomy permission settings. It's better to keep the default
  • Sort: sorting when querying taxonomy articles
  • _Builtin: Is this a built-in taxonomy or a user-defined taxonomy. It is better to keep the default or set it to False. This parameter is only useful for WordPress core

Labels detailed parameters

  • 'name' – the generic name of the classification, usually plural
  • 'singular_name '– the name of an object of this taxonomy
  • 'search_items' – Search for item text. The default is __ ('Search Label ') or __ ('Search Category')
  • 'popular_items' – popular item text. The default is __ ('popular tag ') or null
  • 'all_items' – All item text. The default is __ ('All Labels') or __ ('All Categories')
  • 'parent_item' – Parent item text. This string is not used for non hierarchical taxonomies, such as post tags. The default value is null or __ ('Parent Category ')
  • 'parent_item_colon' – Same as the result parent_item, but: ends with a colon, __ ('parent category: ')
  • 'edit_item' – Edit the item text. The default is __ ('Edit Label ') or __ ('Edit Category')
  • 'update_item' – Update the item text. The default is __ ('Update Label ') or __ ('Update Category')
  • 'add_new_item' – Add new item text. The default is __ ('Add New Label ') or __ ('Add New Category')
  • 'new_item_name' – New item name text. The default is __ ('new label name ') or __ ('new category name')
  • 'separate_items_with_commas' – Separate items using comma text in the category item metabox. This string is not used for hierarchical taxonomies. The default value is __ ('Separate label with comma ') or null
  • 'add_or_remove_items' – Add or delete item text and use it in the metabox when JavaScript is disabled. This string is not used for hierarchical taxonomies. The default value is __ ('Add or Remove Tag ') or null
  • 'choose_from_most_used' – Select from the most commonly used text used in the taxonomy meta box. This string is not used for hierarchical taxonomies. The default value is __ ('Select from the most commonly used labels') or null
  • 'menu_name '– Menu name text. This string is the name of the provided menu item. The default value is name

Foreground call

The template file of the classification list page of the user-defined taxonomy is taxonomy.php or taxonomy-{taxonomy_slug}.php taxonomy.php It is the template file called by default for all user-defined taxonomies, taxonomy-{taxonomy_slug}.php The template file that specifies the custom taxonomy calls, such as the custom taxonomy products created in this tutorial, uses the taxonomy-products.php The file specifies the call.

Particular attention

It is important to emphasize that after adding a new user-defined category, the fixed connection must be updated. Just click Save Settings, or the foreground will not call it.

This article is written by: Shallow singing Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/330.html
Shallow singing
author

Related recommendations

1 year ago (2024-02-20)

How does the WeChat management system manage enterprise WeChat chat content, and chat records of enterprise WeChat administrator permissions

Original title: How does the WeChat management system manage enterprise WeChat chat content How does the enterprise WeChat chat content manage enterprise WeChat chat content? Most WeChat chat content viewers on the market are for private viewing, but viewing WeChat chat content in enterprises is also particularly important. Without the use of WeChat management system, many behaviors such as abusing customers, flying orders, and randomly promising customers are
six hundred and sixty-two
zero
1 year ago (2024-02-20)

Liaocheng Chiping District Sub branch of Agricultural Development Bank of China carried out the second online exercise of the new generation credit management system, and how to do a good job in credit work as a member of Agricultural Development Bank of China

Recently, Chiping District Sub branch of Agricultural Development Bank of China actively implemented the second phase online exercise of the new generation credit management system. In accordance with the requirements of the overall exercise plan issued by the superior bank, it carefully deployed, carefully organized, clearly defined the division of labor, strengthened the coordination and linkage between various departments, closely cooperated, and effectively performed various work responsibilities during the exercise. Chiping District Sub branch organized all staff of the Customer Department to participate in the online drill
four hundred and ninety-one
zero
1 year ago (2024-02-18)

Content marketing is hard to do? Zhiqu Baichuan teaches you how to easily build a content management system, and what needs to be done well in content marketing

Two days ago, we received an official email "to Baichuan to remove from the salesforce app store" - because the United States issued an administrative order on August 6, 2020, prohibiting "any WeChat related transactions", which came into effect 45 days after the administrative order was issued (that is, September 20). The "one-stop marketing cloud" provided by Zhiqu Baichuan includes
three hundred and forty-one
zero
1 year ago (2024-02-18)

Why Enterprise Content Management System?, Why did you choose Business Management

As paper has almost disappeared, your company's important documents and information need to be digitized, stored and used in a way that supports processes and workflows. Through the enterprise content management (ECM) system, you can better manage enterprise content and choose a more interactive way to process the information of the entire enterprise. Do you check the internal documents, invoices, training materials, contracts, finance
two hundred and eighty-seven
zero

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: