Custom fields: extra details on every item
Add structured details such as client, budget and date to your content, store them as post meta, show them and sort by them, with a real test.
In this lesson you will
- Explain post meta
- Choose how to add fields
- Show and sort by fields
- Plan fields sensibly
About 15 minutes
Extra details for every item
Selim’s project pages have a title, text and a picture, but he also wants a client name, a budget and a completion date on each one, shown in a neat box. He does not want to type them into the text every time, where they would look different on each page. The answer is custom fields: small labelled pieces of data stored with each item, which a template can show in the same place and style everywhere.
How WordPress stores them
Every post, page or custom type can hold extra values called post meta, each with a name (the key) and a value. Plugins for custom fields give you friendly boxes in the editor; underneath, they use this storage. A test registered two fields, ‘client’ and ‘budget’, saved them for three projects, searched by budget and cleaned up. The output is real:
client saved (sanitized): Mina Cakes
budget type: string
budget >= 1000, biggest first: Zz C (2000), Zz A (1200)
total budget: 4000
meta keys stored: client, budget
leftover meta rows: 0
Read it carefully. The client name was saved with its tags removed, because a cleaning rule ran on save. The budget came back as text (‘string’) even though it was entered as a number, which is how this storage behaves; so when you calculate, convert it to a number first, as the test did to reach the total of 4000. A filter found the two projects with a budget of at least 1000 and sorted them with the biggest first, and the cleanup left no stray data.
Plugin or code?
| Option | Good for |
|---|---|
| Field plugin | No-code boxes, groups, images, date pickers |
| Small code plugin | A few simple fields you control exactly |
| Block bindings and dynamic blocks | Showing fields inside block layouts |
For most site owners a well-
Showing fields on the page
- In a classic theme, a template file prints the value where you want it.
- In a block theme, dynamic blocks and bindings can display a field inside a normal layout.
- Many field plugins supply their own block or shortcode for showing values.
- Always escape values when printing, which means converting special characters so they are shown as text (a developer’s habit, but good to know exists).
Designing a good set of fields
- List what visitors need to know about each item.
- Choose the right field type: text, number, date, choice, image or link.
- Name fields clearly, with lowercase names such as client.
- Decide which are required, and give editors short help text.
- Test with three real items before entering a hundred.
Use fields for structure, not decoration
A field is useful when the same kind of information appears on many items and you want to show it consistently, sort by it or filter by it. If a detail appears on one page only, write it in the page text. Too many fields make editing a chore, and editors will skip them.
Searching, sorting and filtering
As the test showed, you can ask WordPress for items where a field is greater than a value and order them by that field. The same idea powers ‘sort by price’ on a shop or ‘events after today’. Numbers and dates need to be stored in a form that sorts correctly; dates are best stored as year-
Practice
Pick the custom type from the last lesson. Add three fields: a client, a number and a date. Fill in five items, show the fields in a box on each single page and sort the archive by the number. Then try removing the plugin on a copy of the site and note what happens to the stored values.
The values usually remain in the database even if the plugin is removed, but they stop appearing on the page. This is why choosing a plugin that stores standard meta makes later changes easier.
Typing structured details into the main text of each page. They end up in different places and styles, and you cannot sort or filter by them.
Example: fields for a recipe site
| Field | Type |
|---|---|
| Preparation time | Number of minutes |
| Serves | Number |
| Difficulty | Choice: easy, medium, hard |
| Source link | Web address |
With these four fields every recipe can show the same neat box, visitors can filter for ‘under 30 minutes’, and you can sort by difficulty. Without them, the details sit in sentences that differ from page to page and cannot be searched or sorted. Think about the questions a visitor wants answered at a glance, and give each one a field.
Keeping fields maintainable
- Write down every field name and its meaning in a short note.
- Do not rename a field after you have filled in many items without a plan to move the data.
- Back up before bulk changes.
- Use fields for facts, and the editor for stories.
A small, tidy set of fields is easier to fill in, easier to show and far easier to hand over to somebody else later.
Check what you learned
Five quick questions. Pick an answer and you will see straight away whether it is right and why.
What are custom fields?
- A new theme
- A form button
- A password
- Labelled extra data stored with an item
They are stored as post meta.
What type did the budget come back as in the real test?
- Image
- Text (string)
- Date
- Video
Convert to a number to calculate.
What are fields good for?
- One-off notes on a single page
- Changing the logo
- Backups
- Consistent structured details you can sort or filter
Use text for one-off details.
What should you check about a field plugin?
- That it stores standard meta
- That it has a long name
- That it changes colours
- That it is paid
It reduces lock-in.
How should dates be stored to sort well?
- Day names
- Free text
- Year-month-day
- Pictures
That order sorts correctly.
Summary
- Custom fields store labelled extra data.
- Values come back as text; convert for calculations.
- Choose plugins that keep standard meta.
- Use fields for structured, repeated details.
Questions
Do I need ACF or a similar plugin?
Not required, but such plugins make fields easy to set up. Choose a well-maintained one, and check current terms.
Where are custom fields stored?
In the post meta table of the database, linked to each item.
Can visitors see my custom fields?
Only if your template prints them, or a field is exposed through the REST interface.
