Best WordPress Plugin for Custom Fields & Meta Boxes
Custom Fields Fundamentals
Basics about custom fields: what they are, how they work, what are applications, etc. to help you use custom fields in WordPress skillfully and effectively!
Custom fields is a way for WordPress to store arbitrary extra data for content (posts and custom post types), such as author name, published date for a book. To make custom fields flexible and compatible with different kinds of data, WordPress designs the meta tables (post meta, term meta, user meta, and comment meta) in the form of key-value. According to that, each custom field is stored as one row in the database. This approach allows developers to store unlimited data regardless of its structure. But, the downside is the rapid bloat of the database. Because the number of custom fields is usually very large. This article will present solutions to optimize the storage of custom fields in the database to help boost your website performance.
Custom Fields is an important and useful feature in WordPress and bring us a very high customization ability. So, let's find out the basics, relevant techniques, and excellent applications of Custom Fields in this series.
If you've already reached WordPress, you also heard that it is a top platform for quickly building blogs. Furthermore, its partial actual power is Custom Fields, which took part in the WordPress' strong development and taking up leading position in CMS over previous 15 years.
About WordPress
Currently, WordPress is the most popular CMS in the world that powers around 43.1% of websites. It is the statistic on public sites only. There is also a large number of invisible sites such as deep web or private sites which no one knows for sure. We merely know that the number of such sites is much larger than the public.
It's not to say that WordPress is born with a destined destiny to lead the world. It's the result of its long-term growth history with features are able to satisfy lots of users, over 45,000 plugins, and about 6,000 themes published officially on wordpress.org.
Why can WordPress be able to meet the various different needs from news sites, portfolio sites, and hotel reservations sites to e-commerce sites of such a large number of users? What are the secrets? One of the answers is Custom Fields and the metadata architecture behind.
First of all, let's inquire basically how data is organized in WordPress and why metadata is so important.
Metadata
We could interpret Metadata as arbitrary data (meta) attached to the (primary) data providing more information and clarifying that (primary) data. The primary data does not contain this meta itself.
There are main types of object in WordPress are Post, User, Comment, Taxonomy, and Media. They hold only essential fields provided by WordPress to describe them. E.g. Title for Product or Post, user_name for User, and Name for Category. In the database, these all things are expressed in correspondent tables with columns (tables for objects and columns for fields).
However, what if you want to depict the object Post as a Product? So you need additional information on price, quantity, and color for instance. So that, instead of adding columns to the table ordinarily, the data of additional information will be saved into metadata, then linked to Post. Post becomes Product from now on.
It means that Post is Post only without metadata. In contrast, Post could become Product when you use metadata. Then, if you do not want it to be Product anymore, you may associate it with fields for Room as price and space, so Post becomes Room without changing the fundamental data of Post. That highly interested flexibility is the foundation for the power of WordPress' growth.
Custom Fields
Now, we come back to Custom Fields.
In WordPress, to allow users to add, delete, or edit metadata data, there must be a tool for manipulating them. That is the custom fields!
So, the principal question here is what custom fields is?
Custom fields is a feature that helps us create forms and fields to interact with metadata.
Here is a screenshot of how custom fields are implemented in WordPress.
If there is no user interface (UI) of the custom fields as above, the only way to add, remove, or edit metadata is using the code through the functions provided by WordPress. For WordPress beginners, this is quite difficult. A UI will help them manipulate the data more visually and conveniently.
In fact, the concept of metadata is rarely mentioned because it is a technical term hidden under custom fields in WordPress. And when it comes to custom fields, it's generally understood that it includes both the user interface and the metadata. In this series, we also agree with that and use it for both.
Sorts of custom fields and metadata
As mentioned above, custom fields create form fields so that user can add metadata that they need. So which objects will this data be added?
In the metadata section, we said that the main types of objects are Post, User, Comment, Taxonomy, and Media. All of these objects may have own custom fields, so we have corresponding custom fields and metadata also for Post, for User, and so on. You also can see custom fields when you edit them.
Here is a screenshot of the custom fields for posts:
For some simple fields such as text, the WordPress default functions are sufficient to use. Nevertheless, if you want to use more complex fields, you must manually code it. It's not too hard for fields like image and editor, but it's complicated for fields like repeater or relationship fields.
Travel: add descriptive fields for Address, Rating, Price, Tour guide.
Hotel: add fields such as Price, Availability, Capacity, Facilities.
E-commerce: fields about Price, Volume, Quantity.
In WordPress, we can say that wherever custom post types are, there custom fields are!
Conclusion
Metadata and custom fields have provided WordPress a powerful capability of customization to meet the needs of nearly 30% website in the world, in all industries. When you are working with WordPress, you either only build a trivial blog or cannot ignore Custom Fields.
On the other hand, custom fields are also a cause of many disputes. Some people say it makes query slower, and some say it is not suitable to scale. So that to know the truth, there is no other way than to learn more about WordPress' building and querying data from custom fields' database. Please be patient, we will learn all about them step by step in this series, in later articles.
Besides, there is a term called custom taxonomies. Someone may confuse when to use custom fields or custom taxonomies. If you have the same question, you should read our article about Custom Fields vs. Custom Taxonomies.
In the previous post, we have learned the basic concepts of custom fields and their applications. In this post, we will learn how to add custom fields to a WordPress site without coding or using a third-party plugin.
The default custom fields functionality in WordPress is to help end-users add content and customize their websites fast and easily. However, it is limited to only text fields and thus, is not enough in most cases. Then you may want to look for a plugin that can help you create fields in any type to save any kind of data as Meta Box plugin, it’s so easy. But you know what, even when you don’t want to use any plugin from others, you can create one by yourselves to create new custom fields in your totally new types.
In the previous articles, we've known about what Custom Fields is and the application of custom fields which allows users to add arbitrary information into posts. But what do you do after that? In the recent post, you also learned how to add custom fields programmatically and display them in your theme. But you’ll see a shortcoming if there is no classification and searching. This post will guide you on how to get posts by custom fields in WordPress and we'll create an interesting application: advanced search.
As we know, custom fields is used to add more data to some objects in WordPress such as posts, pages, taxonomies, users, and comments. The two main purposes of custom fields are to describe and filter those objects. In this post, we'll learn what specific applications custom fields has in reality.
Until now, we’ve known what custom fields is and how to use the functions provided by WordPress to work with custom fields. You’ve prepared everything needed to develop practical applications. But wait, before embarking on doing something new, you had better dig a bit deeper to have thorough understand custom fields' nature. It’s time to find out an answer to the question: “What really happens with custom fields when I click Save post?”. The two coming posts will give you the answers.
Now, you know what custom fields is and in the previous post, we stopped in the step “WordPress calls the update_metadata function to store data from custom fields in the database”. In this post, we’ll follow up that flow to figure out how WordPress organizes the database.
The importance of meta box and custom fields in WordPress has been emphasized in the previous posts. Due to their significance, they are used a lot and frequently in the development process of a plugin or theme to satisfy the need of users.
In part 1 of this series, we learned about how to get posts by custom fields in WordPress with the WP_Query function. However, if we need to deal with databases, it’s better to find another faster, easier, and more convenient way. That method is joining wp_posts and wp_postmeta tables together, and then querying by SQL. In part 2 of the series “How to get posts by custom fields in WordPress”, we’ll use this way to add the advanced searching feature that allows users to search by keywords in posts / pages titles and custom fields content.