WordPress building blocks · Part 3
What are custom fields, and why does everyone use ACF?
The 30-second version
Custom fields turn the blank content box into a form with labelled boxes, so every entry looks the same and its details can be reused. ACF makes them easy: build a field group, add fields, and set a location rule like “post type is Recipe”. Secure Custom Fields is a 2024 fork; use one, not both. A relationship field links team members to locations, optionally both ways. Show fields with get_field() and always escape the output. Change a field’s label, never its name. Local JSON keeps field groups in your theme’s files.
On this page
In the last post, the made-up example-bakery.com got new drawers for its content: Recipes, Locations and Team members. Each drawer is still holding a blank sheet of paper, though. A recipe needs prep time, ingredients and a photo, and a team member needs to know which shop they work at.
That’s what custom fields are for. This post covers what they are, why almost every WordPress developer reaches for the same plugin to make them, the field types worth knowing, and how to link team members to their locations.
A blank sheet vs a form
The big content box in WordPress is a blank sheet of paper. You can write anything on it, which sounds great until every recipe is laid out a little differently and nobody can remember where the prep time goes.
Custom fields turn that blank sheet into a form with labelled boxes: Prep time ___, Serves ___, Photo ___. Editors fill in the boxes, and the site decides how to show them.
Why bother with custom fields?
- Every entry looks the same. The template puts prep time in the same spot on every recipe, so editors don’t have to format it by hand.
- You can reuse the details. Show prep time on the recipe page and on the little recipe cards on the
/recipes/list, from the same box. - Editors can’t get it wrong. A number field only takes numbers. A required field can’t be left empty.
- Clean data. Because each detail lives in its own box, you can sort and filter by it later, like “recipes under 30 minutes”.
Why does everyone use ACF?
WordPress actually has custom fields built in. There’s a hidden “Custom Fields” panel you can switch on in the editor’s preferences. It’s a plain list of names and values, though: no field types, no rules, nothing to stop an editor typing “about an hour” into a box that should hold a number.
Advanced Custom Fields (ACF) turns that into something friendly. You build a form by clicking, pick a type for each box (text, number, image, true/false and lots more), and choose where the form shows up. It’s been around for years, it has over 2 million active installs, the free version covers most sites, and most WordPress developers already know it. On a site someone else built, there’s a good chance it’s already installed.
ACF and Secure Custom Fields: what happened
If you search for ACF, you’ll also find a plugin called Secure Custom Fields (SCF). Here’s the short version.
- In October 2024, during a legal dispute between WP Engine (who make ACF) and Automattic, WordPress.org took over ACF’s listing in the plugin directory and replaced it with its own fork, renamed Secure Custom Fields.
- ACF is back on WordPress.org under WP Engine, and SCF is now a separate plugin made by WordPress.org. Both are actively updated.
- SCF started as a copy of ACF, so the screens and the code you write in your templates look almost the same. It also includes features that are paid extras in ACF, like the repeater.
- The dispute is still going through the courts, so it’s worth checking the latest before you choose.
Pick one, not both
ACF and SCF can’t run side by side. Installing SCF deactivates ACF and ACF Pro. On an existing site, stick with whichever one is already there, the same as with post types.
The rest of this post says “ACF”, but nearly everything works the same in SCF.
Field groups and location rules
In ACF, you don’t add fields one at a time. You make a field group (a form), add fields to it, then set a location rule that says where the form appears, like “Post type is equal to Recipe”.
Location rules can be much more specific than that: only on one page template, only for a certain category, only for logged-in admins. For most sites, “this post type” is all you need.
From field group to web page
- Field group“Recipe details”: prep time, serves, photo
- Location ruleShow this group when post type is Recipe
- Edit screenEditors see the boxes under the content
- TemplateYour theme reads the values and shows them
Field types worth knowing
ACF has over 30 field types. These are the ones you’ll use most:
- Text and text area: short and long plain text. A job title, a short description.
- Number: prep time in minutes, how many it serves. You can set a minimum and maximum.
- Image: an image from the media library. You choose whether your template gets the image’s ID, its URL or all its details.
- True / false: a single on/off switch, like “Gluten-free”.
- Select: a dropdown with set choices, like Easy, Medium, Hard.
- Relationship: links this entry to other entries, like a team member to their locations. More on this below.
- Repeater (Pro): a set of boxes you can add again and again, like one row per ingredient.
- Flexible content (Pro): a list of different building blocks an editor can stack in any order.
Repeater, all day every day
If I had to pick one Pro feature, it’s the repeater. Ingredients, opening hours, FAQs, team socials: anything that’s “a list of the same few things” is a repeater. It’s the main reason I reach for ACF Pro.
Free vs Pro
ACF’s free version includes most field types, location rules and the screens for making post types and taxonomies. ACF Pro is a yearly licence that adds the repeater, flexible content, gallery, clone and options page fields, plus ACF Blocks. An options page is a settings screen for site-wide details, like the bakery’s phone number in the footer.
Start with the free version. If you find yourself needing a repeater, that’s usually the moment Pro pays for itself. As with any paid plugin, keep the licence active so you keep getting security updates (more on that here).
Linking team members to their locations
Back to the request from the last post: each team member should show up on the location pages for the shops they work at. With both post types in place, the link is a relationship field. I’ve built exactly this, and it’s simpler than it sounds.
Step 1:Make a field group for team members
Go to ACF → Field Groups → Add New, call it “Team member details”, and set the location rule to “Post type is equal to Team member”.
Step 2:Add a relationship field called “Locations”
Add a field, choose the Relationship type, label it “Locations” (the name becomes locations), and under Filter by Post Type choose Location. Now editors can only pick locations, not recipes or blog posts.
Step 3:Decide whether the link should work both ways
Out of the box, the link only lives on the team member. If you also want to see a location’s team when editing that location, add a matching relationship field to Locations and turn on Bidirectional (in the field’s Advanced tab), pointing the two fields at each other. Then picking a location on a team member also adds that team member to the location.
Step 4:Show it on the site
Add a few lines to the team member template (below). Each team member page now lists the shops they work at, with links.
Showing fields on the site
ACF gives you get_field(), which hands your template the value of a field. These examples are for a classic theme’s PHP templates, like the single-recipe.php from the last post.
<?php
// Inside the loop on a single recipe page.
$prep_time = get_field( 'prep_time' ); // Number field
$serves = get_field( 'serves' ); // Number field
$photo_id = get_field( 'photo' ); // Image field, Return Format: Image ID
?>
<?php if ( $photo_id ) : ?>
<?php echo wp_get_attachment_image( $photo_id, 'large' ); ?>
<?php endif; ?>
<p>
Prep time: <?php echo esc_html( $prep_time ); ?> minutes.
Serves <?php echo esc_html( $serves ); ?>.
</p>
<?php // Repeater field (ACF Pro): one row per ingredient. ?>
<?php if ( have_rows( 'ingredients' ) ) : ?>
<ul>
<?php while ( have_rows( 'ingredients' ) ) : the_row(); ?>
<li><?php echo esc_html( get_sub_field( 'ingredient' ) ); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?><?php
// Relationship field with Return Format: Post Object.
$locations = get_field( 'locations' );
?>
<?php if ( $locations ) : ?>
<h2>Where to find me</h2>
<ul>
<?php foreach ( $locations as $location ) : ?>
<li>
<a href="<?php echo esc_url( get_permalink( $location ) ); ?>">
<?php echo esc_html( get_the_title( $location ) ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>A few things to notice:
- Always check a field has a value before you show it (the
iflines), so you don’t get an empty “Prep time: minutes”. - The name in
get_field( 'prep_time' )is the field’s name, not its label. You’ll find it next to the label in the field group. - Repeaters use
have_rows(),the_row()andget_sub_field()instead ofget_field(). - If your site uses a block theme instead of PHP templates, ACF Blocks (below) are one way to show fields.
`get_field()` doesn’t escape anything
get_field() gives you exactly what was saved. If you echo it straight onto the page, anything an editor (or someone who got into an editor’s account) typed goes out as-is, scripts included. Wrap values in the right WordPress escaping function: esc_html() for text, esc_url() for links, esc_attr() inside HTML attributes.
You might also see the_field(), which prints the value for you. Since ACF 6.2.7 (early 2024), it strips unsafe HTML automatically, so older themes that used it to print scripts or embeds stopped working. Escaping it yourself with get_field() keeps you in control.
Change the label, never the name
Each field has a label (what editors see, like “Prep time”) and a name (what’s saved in the database, like prep_time). Changing the label is safe any time. Changing the name means ACF looks in a new spot, so every recipe suddenly looks empty. The old values are still in the database, just not connected any more. It’s the same as renaming a post type.
Field groups live in the database
By default, your field groups are saved in the site’s database, not in your theme’s files. If you build them on a local copy, they don’t come along when you upload your theme. You either rebuild them on the live site or use ACF’s export and import tools.
ACF has a feature for this called Local JSON. Add an acf-json folder to your theme and ACF saves a copy of each field group there as a file whenever you save it, so the field groups travel with your theme and can go in git. When a file is newer than what’s in the database, a Sync link appears so you can bring it in.
ACF Blocks, briefly
ACF Pro can also make your own blocks for the block editor. You register a block, give it a field group and a small PHP template, and editors get a block like “Recipe card” or “Team member” that they can drop into any page. It’s the friendliest way to build custom blocks if you’re comfortable with PHP but not React. It deserves its own post, so that’s all for now.
As with plugins and post types, try new field groups on a local copy of the site first. If you don’t have one yet, here’s how to make one.
What I’d tell past me
Custom fields are way more powerful than you think. Like CSS, there’s always another trick to discover: conditional fields that only appear when you need them, relationships that link both ways, repeaters inside repeaters. Start with a text field and a number, then keep exploring.
That’s the end of the WordPress building blocks series: plugins to add features safely, custom post types for new kinds of content, and custom fields for the details each one holds. Together they cover most of what a custom WordPress site is made of.