Along with custom post-types, custom fields are an incredibly useful tool for WordPress development. They work exactly like they sound. Custom fields allow users to create custom editable regions for posts, pages, custom post-types and/or all of the above. For example, one could create a custom field that applies only to posts. Alternatively, one could also create a custom field that applies to posts and pages.
Let’s say one had a client that wished to associate and featured quote with some of their blog posts. A developer could create and title a custom field, “Featured Quote,” and associate the field with all posts. Therefore, anytime the user creates a blog post, an optional field would exist to enter in quote content. If a value is entered, the content can then be called anywhere on the site by simply inserting a simple script into the desired WordPress template.
Here are some of the benefits of using custom fields:
- Simplified content entry
- Can be called (displayed) anywhere on the WordPress site
- Can be mandatory; meaning one HAS to enter in a value to create/update a post, page, or custom post-type
- Media can be easily inserted
- Can be easily created using a plugin
Some important notes:
- Should be used inside the Loop
- Not intended for e-commerce (i.e. associating a custom field of “Price” with a custom post-type of “Product.”
- Can also be created by hardcoding script into a theme’s function file