black friday sale

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).

Objects and Fields in correspondent tables with columns in WordPress
Objects and Fields in correspondent tables with columns in WordPress

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.

Forms and fields of custom fields to fill data
Forms and fields of custom fields to fill data

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:

Illustration for custom fields when editing posts
Illustration for custom fields when editing posts

Here is a screenshot for custom fields for categories:

Illustration for custom fields when editing categories
Illustration for custom fields when editing categories

Common types of custom fields

As you can see in the screenshot above, there are many types of data need to add to each object usually. It can be a short text, an image, or a URL.

In the process of carrying out the content, users often encounter the following field types:

  1. Text field (e.g. name, address)
  2. Image field (e.g. profile image, icon)
  3. File upload field: PDF file download, invoice download
  4. Editor field: brief description, intro text
  5. Relationship field: field links to another object types
  6. Repeater field: field can be repeated
  7. URL field: website, social media profile
  8. Choice field: select an option from a predefined list
  9. And many more

To add such custom fields to WordPress, we have the following three options:

  1. Use the default feature of WordPress
  2. Use the functions of WordPress
  3. Use plugins

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.

Applications of custom fields

You definitely can create websites in different industries with custom fields. For example:

  1. Travel: add descriptive fields for Address, Rating, Price, Tour guide.
  2. Hotel: add fields such as Price, Availability, Capacity, Facilities.
  3. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *