WordPress 4.4 introduces some new features for developers. The infrastructure of WordPress rest API has received the most attention at present, but there are several new features worthy of attention that deserve careful study. In particular, classification term metadata. This article will discuss what meta (meta) is and how to use it. The necessity of the word meta has been demonstrated by many solutions that existed in the past, which are designed to approximate this function by a variety of means. For example, pods has long supported custom fields for categorical terms. Previously, these custom fields were stored in custom database tables. The
You can now use the standard term meta or a custom table. The new default option of the term meta not only accepts the \
WordPress 4.4 introduces term metadata, which is used to copy the metadata system of classification terms. Previously, classified terms could only have names, slashes and descriptions. You can now add any number of additional fields to each term. For example, if you want to associate a color with each category and then use the color in the theme to make the category archive page unique, you can save the color in the term meta field. Another example is the main product system for building e-commerce plug-ins based on product categories. If you asked me to build before the glossary, you might have added a field in the product post to indicate whether to recommend it. The
New changes in meta terms make relationships work differently. Each category term can save the post ID list as term metadata. This method is preferred because it changes the method of querying products and moves the interface from the post editor to the term editor, or both. The term meta operation meta has several new functions that can be used with terms. They all follow the same pattern as the article and user meta functions. In addition, regular meta functions such as update\u metadata, delete\u metadata() and add\u metadata() can now be used with the term meta, as well as with user and article meta. The
Let’s briefly introduce the new features. Posts and users’ meta cousins are popular features that use the same pattern, so they should be easy to use. It also describes the functionality of meta queries using get_terms(). This is new, but it follows the meta query of wp_query and wp\u user\u query, so it is easy to learn. Like meta after saving the term meta, there are two similar functions. Add\u term\u meta() and update\u term\u meta() generally, update\u term\u meta() is a better choice for creating new terms and updating term meta(). The potential benefit of using add_term_meta() is that the optional parameter $unique prevents the addition of existing meta terms. The
Each function uses the word ID. If there is only a slug, you must use get_term_by() to search for the term ID. For example: $term=get_term_by (\