If you build or maintain a WordPress theme, Advanced Custom Fields (ACF) lets your editors fill in structured details like an event date or a poster image. Out of the box, WordPress gives them one big content box. Details typed there end up buried in the text, where your template cannot pick them out.
ACF fixes that with three pieces. A field group is the set of input boxes you design, such as a date picker plus an image upload. Location rules are the conditions that decide which edit screens show that set, for example only posts of type event. In your template, the get_field() function fetches a saved value by the field’s name, in one line of PHP. Each value is stored in wp_postmeta, the table where WordPress keeps extra data attached to a post, so you can always inspect it directly.
You will build one field group end to end and keep its definition in git with local JSON, an ACF feature that writes each group to a file in your theme. You will also fix the two causes behind most “my field is empty” reports. One is an Image field returning an array when the template expects a plain URL. The other is calling get_field() in a widget or footer, where WordPress has no current post to read from.
What you’ll accomplish
- A field group with deliberately named, typed fields that appears only on the edit screens you chose.
- Location rules you can reason about, including how a second rule row differs from a second rule group.
- A working picture of what ACF writes into
wp_postmeta, so you can read the rows directly when a value looks wrong. - Template code that prints text, Image and Repeater values correctly, inside and outside The Loop.
- The field group definition committed to your repository through
acf-json, so a deploy carries it instead of a database export.
Prerequisites
- WordPress 6.x, PHP 8.1 or newer, and write access to the active theme or a site-specific plugin.
- WP-CLI on the server for the verification commands below.
- A child theme or custom theme you are allowed to edit. Template changes in a third-party parent theme get overwritten on the next update.
Be honest with yourself about free versus Pro before you design the field group, because the answer changes the shape of your content model.
The free plugin covers most field types: Text, Textarea, Number, Range, Email, URL, Password, Image, File, WYSIWYG, oEmbed, Select, Checkbox, Radio, Button Group, True/False, Link, Post Object, Page Link, Relationship, Taxonomy, User, the date, time and colour pickers, and the layout helpers Group, Tab and Accordion. Location rules are free. The local JSON workflow is free. For a page with a hero image, a subtitle, a date and a related-post picker, free ACF is the whole job.
ACF Pro adds Repeater, Flexible Content, Gallery, Clone, options pages and ACF Blocks. Repeater and Flexible Content are what most teams actually mean when they say “we need Pro” — the free plugin has no way to repeat a set of sub fields, and no amount of Group nesting substitutes for it. Pro is a paid licence sold in tiers by site count; check the current terms before you commit a portfolio to it. If you can model the content without repeating rows, start free and stay free.
How it works
A field group is itself a WordPress post, of post type acf-field-group. Each field inside it is a post of type acf-field. Every field carries two identifiers that people constantly conflate: a field key such as field_65f0a1b2c3d4e, generated once and never changed, and a field name such as event_date, which you choose and which becomes the meta key in the database. The field label (“Event date”) is display text in the admin only. Nothing in your template ever refers to the label.
When an editor saves post 128, ACF writes two rows per field:
| meta_key | meta_value |
|---|---|
event_date | 2026-09-14 |
_event_date | field_65f0a1b2c3d4e |
The visible row is plain WordPress post meta. get_post_meta( 128, 'event_date', true ) returns the identical string with no ACF involved, which is why any plugin that reads post meta can see ACF data. The underscore row is the reference: it maps the meta key back to the field definition, so ACF knows the field’s type and can apply that type’s formatting on read. When the reference row is missing, for example after a manual wp_postmeta insert or an import that dropped underscore keys, get_field() does not look the field up by name or search your field groups. It treats the field as unknown and returns the raw stored value with no type formatting. An Image field then returns the bare attachment ID instead of the array or URL your template expects. Passing the field key instead of the name, as in get_field( 'field_65f0a1b2c3d4e' ), skips the reference lookup.
Location rules run when an edit screen is rendered, never on the front end. Within one rule group, rules combine with AND; a second rule group added with “Add rule group” combines with OR. So “Post Type is equal to event” plus a second row “Post Status is equal to publish” means both must be true, while a second rule group means either group can match. If no group matches the screen, the metabox does not render, the editor cannot type anything, and no value will ever exist for that post — which is the single most common reason get_field() returns nothing.
Step-by-step
- Install ACF and record the version. Field behaviour, especially output escaping, differs across 6.x releases, so note what you are on.
wp plugin install advanced-custom-fields --activate
wp plugin list --name=advanced-custom-fields --fields=name,status,version
Expected output: a single row with status reading active and a version in the 6.x range. If the status column says inactive, activation failed and every later step will silently do nothing.
- Create the field group and choose field names deliberately. In the admin, go to Custom Fields, then Add New. Name the group something a stranger can interpret, such as “Event details”. Add fields with lowercase, underscore-separated names:
event_date(Date Picker),event_tagline(Text),event_poster(Image). The name is permanent in practice — renaming it later orphans every existing row inwp_postmeta, because the old meta key stays behind untouched.
For the Image field, open its Return Format setting now rather than discovering it later. Array gives you an associative array with url, alt, width, height and a sizes sub-array. URL gives a bare string. ID gives an integer attachment ID. Pick one and write the template to match.
wp eval '
foreach ( acf_get_field_groups() as $g ) {
printf( "%-24s %-24s source:%s\n", $g["title"], $g["key"], $g["local"] ?? "database" );
}
'
Expected output: one line per group, for example Event details group_65f0a1b2c3d4e source:database. The source column becomes useful in step 4.
- Set location rules, and know AND from OR. In the field group’s Settings panel, set the first rule to “Post Type is equal to event”. Add a second row inside the same group only when both conditions must hold. Use “Add rule group” when you mean either. Save, then confirm which groups a specific post actually gets:
wp eval '
$groups = acf_get_field_groups( array( "post_id" => 128 ) );
foreach ( $groups as $g ) { echo $g["title"] . "\n"; }
'
Expected output: Event details. An empty result means the rules never matched post 128 — fix that before you write a single line of template code.
- Put the definition in git with local JSON. Without this, a field group exists only as database rows, and moving it between environments means a database export or the plugin’s own import screen. Create the directory in your theme:
cd wp-content/themes/mytheme
mkdir -p acf-json && chmod 755 acf-json
printf '<?php\n// Silence is golden.\n' > acf-json/index.php
Now re-save the field group in the admin — ACF only writes JSON on save, so an existing group produces no file until you open and save it. Then:
ls -1 wp-content/themes/mytheme/acf-json/
Expected output: group_65f0a1b2c3d4e.json alongside index.php. Commit that file. On the next environment, ACF detects that the JSON is newer than the database copy and offers a “Sync available” tab on the Field Groups screen; clicking Sync imports it.
To keep field groups in a site-specific plugin instead of the theme, register both paths — a save path without a matching load path leaves ACF unable to find the files:
<?php
add_filter( 'acf/settings/save_json', function ( $path ) {
return __DIR__ . '/acf-json';
} );
add_filter( 'acf/settings/load_json', function ( $paths ) {
$paths[] = __DIR__ . '/acf-json';
return $paths;
} );
Success signal: re-save any field group and the JSON file appears under the plugin directory instead of the theme.
- Read a value in a template. Inside The Loop,
get_field()needs only the field name.the_field()is the echoing shorthand for the same thing.
<?php
$date = get_field( 'event_date' );
if ( $date ) {
echo '<p class="event-date">' . esc_html( $date ) . '</p>';
}
// the_field() is echo get_field(). ACF 6.2.5 and later escape unsafe HTML
// in its output, but escape explicitly for the context you print into.
the_field( 'event_tagline' );
The full signature is get_field( $selector, $post_id = false, $format_value = true ), with a fourth $escape_html argument added in ACF 6.2.6. Passing false for $format_value returns the raw database value with no field-type processing — useful for debugging, wrong for display.
The Image field is where return format bites. All three of these are correct; exactly one matches your field’s setting:
<?php
// Return Format = Array
$img = get_field( 'event_poster' );
if ( $img ) {
printf(
'<img src="%s" alt="%s" width="%d" height="%d">',
esc_url( $img['sizes']['medium'] ),
esc_attr( $img['alt'] ),
(int) $img['sizes']['medium-width'],
(int) $img['sizes']['medium-height']
);
}
// Return Format = ID
echo wp_get_attachment_image( get_field( 'event_poster' ), 'medium' );
// Return Format = URL
echo '<img src="' . esc_url( get_field( 'event_poster' ) ) . '" alt="">';
Success signal: view the post on the front end and the image renders. The word Array printed on the page means you used the URL or ID template against an Array field.
- Loop sub fields with have_rows(). Repeater and Flexible Content are Pro fields, and their sub fields are unreachable through
get_field(). Inside the loop you useget_sub_field():
<?php
if ( have_rows( 'event_speakers' ) ) :
echo '<ul class="speakers">';
while ( have_rows( 'event_speakers' ) ) : the_row();
$name = get_sub_field( 'speaker_name' );
$photo = get_sub_field( 'speaker_photo' ); // Return Format = ID
echo '<li>' . wp_get_attachment_image( $photo, 'thumbnail' )
. esc_html( $name ) . '</li>';
endwhile;
echo '</ul>';
endif;
Expected output: one li per row the editor added. An empty ul with rows visible in the admin usually means you called get_field() instead of get_sub_field() inside the loop.
- Read values where there is no current post. Outside The Loop — a sidebar, a footer, a shortcode callback, a REST handler — WordPress has no current post, so ACF has no post to read from and returns nothing. Pass the ID explicitly:
<?php
// Singular template, no Loop in scope
$date = get_field( 'event_date', get_queried_object_id() );
// Archive template, per result
while ( have_posts() ) : the_post();
echo esc_html( get_field( 'event_date', get_the_ID() ) );
endwhile;
// Options page value (ACF Pro)
$phone = get_field( 'support_phone', 'option' );
// Term and user values use prefixed pseudo-IDs
$blurb = get_field( 'category_blurb', 'term_12' );
$title = get_field( 'job_title', 'user_7' );
Success signal: the value appears in the sidebar as well as in the main content. Note that get_the_ID() inside an archive loop is correct, while a bare get_the_ID() in a widget returns whatever post ran last — a subtle bug that shows one post’s data on every page.
Validate it works
Read the value ACF returns, and the rows underneath it, on the same post:
wp eval 'var_export( get_field( "event_date", 128 ) );'
wp eval '
$f = get_field_object( "event_poster", 128 );
printf( "name:%s type:%s return_format:%s\n", $f["name"], $f["type"], $f["return_format"] );
'
Expected output: '2026-09-14' from the first command, and name:event_poster type:image return_format:array from the second. That second line is the authoritative answer to “which return format is this field on” — it beats squinting at the admin UI.
Now confirm the storage layer matches:
wp db query "SELECT meta_key, LEFT(meta_value, 40) AS value
FROM wp_postmeta WHERE post_id = 128 AND meta_key LIKE '%event%';"
Expected output: paired rows, event_date with the date and _event_date with a field_ key, one pair per field. A visible row without its underscore partner is a value ACF cannot type correctly.
Finally, load the page with a profiler attached and check how many meta queries the template generated; a template reading twelve fields should not be running twelve separate queries, because WordPress caches post meta per post. See the Query Monitor plugin guide for reading that panel.
Troubleshooting
get_field() returns empty and the admin shows no fields. The field group’s location rules do not match that post type or template, so the metabox never rendered and no value was ever saved. Run the acf_get_field_groups( array( "post_id" => 128 ) ) check from step 3. An empty result confirms it. Fixing the rules does not retroactively create values — editors must re-save the affected posts.
The value is right in the editor but empty in a widget, footer or shortcode. No current post is in scope, so ACF defaults to nothing. Pass get_queried_object_id() on singular views, get_the_ID() inside a loop, or 'option' for options-page values. Never assume ACF will find the post for you outside The Loop.
The page prints the word Array. The field returns an array and the template is echoing it as a string. Either change the field’s Return Format to URL or ID, or read the key you need — $img['url'], $link['title'], $term->name. Confirm which format you are on with get_field_object() rather than guessing.
Field groups vanish after switching to local JSON. ACF writes a JSON file only when a group is saved, so groups created before you made the acf-json directory have no file. Open and re-save each one. On a second environment, an existing database copy takes precedence until you use the Sync tab — a group edited in both places will not auto-merge, and the newer modified timestamp wins on sync.
get_field( 'Event Date' ) returns nothing. That is the label, not the name. Only the name — event_date — is a valid selector, along with the field key. Renaming a label is free; renaming a name is a data migration, because the old meta rows keep the old key and become invisible to ACF.
When this is the wrong approach
ACF stores everything in wp_postmeta, so it inherits that table’s characteristics. Data you need to query and sort on at volume — a product catalogue filtered by six attributes across 100,000 posts — will hit meta-query performance limits long before ACF itself becomes the problem; custom tables or a taxonomy are the better model there. Field groups with dozens of Repeater rows multiply row counts fast, and the arithmetic plus the alternatives are covered in ACF at scale and the tradeoffs against Meta Box and Pods.
ACF is also the wrong tool for front-end data entry. It is an admin-side editing experience; building public submission forms on top of it means recreating validation, capability checks and sanitisation that ACF never claimed to provide. And on a headless build, remember that custom fields are not in the REST response by default — you have to opt each field group into REST, or register the meta yourself. The full field and function reference lives in the official ACF documentation.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under managed enterprise WordPress hosting; book an infrastructure consult.