When ACF's get_field() returns nothing, the cause is almost always one of eight things: a field name typo, the wrong post context, location rules, a missing field group, sub-field confusion, the_field() mix-ups, a stale object cache or an unexpected return shape. Below is the order I check them in, then the field-specific versions: an empty first Repeater row, counting Repeater rows, True/False fields and Select defaults.
Jump to:
- Cause 1: Field name typo
- Cause 2: Wrong post ID / context
- Cause 3: Field group location rules do not match
- Cause 4: Field group exists but is not assigned
- Cause 5: Trying to read a sub-field with get_field()
- Cause 6: get_field() vs the_field() confusion
- Cause 7: Object cache returning stale data
- Cause 8: Field type returning a different shape than expected
- The diagnostic order
- Repeater first row empty
- Count rows in an ACF Repeater
- True/False field not working
- Select field default value
Cause 1: Field name typo
The most common cause. ACF field names are case-sensitive, snake_case by convention, and easy to mistype.
// Field is registered as "hero_heading" but called as:
$heading = get_field( 'heroheading' ); // returns null
$heading = get_field( 'Hero_Heading' ); // returns null
$heading = get_field( 'hero-heading' ); // returns nullFix: confirm the exact field name by exporting the field group (Custom Fields > Tools > Export Field Groups) and reading the JSON, or by inspecting the field group in the admin UI. The name is the lowercase, underscore-separated identifier.
Cause 2: Wrong post ID / context
get_field() defaults to the current post in the loop. If you call it outside the loop, on a different post type, or on an options page without telling it, you get nothing.
// Outside the loop or in the wrong context
$value = get_field( 'hero_heading' ); // unsure which post
// Explicit post ID, always safer
$value = get_field( 'hero_heading', 123 );
$value = get_field( 'hero_heading', $post->ID );
$value = get_field( 'hero_heading', 'option' ); // options page
$value = get_field( 'hero_heading', 'user_42' ); // user meta
$value = get_field( 'hero_heading', 'term_5' ); // taxonomy metaFix: always pass the second argument when you are not certain the function is being called inside the loop.
Cause 3: Field group location rules do not match
ACF field groups have location rules ("show this field group if post type is X and post template is Y"). If the rules do not match the post you are reading, the field does not exist for that post and get_field() returns nothing.
Fix: open the field group in Custom Fields admin, scroll to "Location", confirm the rules match the post you are working with. A common mistake is restricting a field group to a specific page template, then assigning that template only to some pages but trying to read the field on other pages.
Cause 4: Field group exists but is not assigned
This is a flavor of Cause 3 that catches people moving sites between environments. The field group registration exists in the database on environment A but was not exported and imported into environment B. The code calls get_field() and gets nothing because the field group does not exist in the new environment at all.
Fix: confirm field groups exist on the target environment. wp acf list (with the ACF WP-CLI add-on) or a check via the admin UI both work. If they are missing, export from the source environment as JSON and either import via the admin or commit the JSON to the theme's acf-json/ directory for automatic sync.
Cause 5: Trying to read a sub-field with get_field()
get_field() reads top-level fields. Sub-fields inside a Repeater, Flexible Content, or Group field require get_sub_field() and must be called inside a have_rows() loop.
// Broken: get_field doesn't reach into sub-fields
$heading = get_field( 'stat_row_heading' );
// Correct: sub-fields inside have_rows
if ( have_rows( 'stat_rows' ) ) {
while ( have_rows( 'stat_rows' ) ) {
the_row();
$heading = get_sub_field( 'heading' );
}
}If a Repeater loop renders but the first row comes out blank, see Repeater first row empty below. For deeper context on Flexible Content specifically, see ACF Flexible Content Loop Not Working? Here's the Fix.
Cause 6: get_field() vs the_field() confusion
get_field() returns the value. the_field() echoes it. If you wrote the_field() and assigned the result to a variable, the variable is null (because the_field() returns nothing) but the value got echoed to the page somewhere unexpected.
// Wrong
$heading = the_field( 'hero_heading' ); // $heading is null, echo happens
// Right
$heading = get_field( 'hero_heading' );
echo esc_html( $heading );This is a quick visual check: if the field value is appearing somewhere on the page you did not expect, you used the_field() by accident.
Cause 7: Object cache returning stale data
If the site is on a persistent object cache (Redis, Memcached) and an ACF field was just updated programmatically (via update_field() or wp acf update), the next get_field() call may return the cached old value rather than the new one.
Fix: clear the relevant cache key, or flush the object cache (wp cache flush) on the staging environment to confirm. On production, prefer targeted invalidation: wp_cache_delete( "post_meta:$post_id", 'options' ); for post meta, with similar patterns for other contexts.
This is rare in practice but it bites at exactly the wrong moment (right after a deploy when you cannot figure out why the value did not change).
Cause 8: Field type returning a different shape than expected
get_field() returns different shapes depending on the field type:
| Field type | Returns |
|---|---|
| Text, textarea, number | string |
| Image | array (URL, sizes, alt, etc.) or URL or ID, depending on return-format setting |
| File | array, URL, or ID |
| Gallery | array of image arrays |
| Relationship | array of post objects |
| Post Object | post object |
| User | user object array |
| Taxonomy | term object or array of term objects |
| True/False | boolean (see True/False field not working) |
| Checkbox | array of selected values |
| Select | string or array depending on multiple-select setting |
| Date | string in the field's format |
| Repeater | array of arrays (or false if empty; see Count rows in an ACF Repeater) |
| Flexible Content | array of arrays with layout key |
If you expected a string and got an array (very common with Image fields), get_field() is "returning nothing" only in the sense that the data is not the shape your code expected. For the image case specifically, ACF Image Field Returning an Array Instead of a URL? covers the return-format options.
Image field returns false (or empty) when the field is empty
An empty ACF image field returns an empty value, not an array you can index into. The exact shape depends on the field's Return Format: with Array it returns false (an unset image field is falsey), with Image URL it returns an empty string, and with Image ID it returns false / empty. So get_field( 'image' ) on an empty field is falsey across every return format. That is why naive code which assumes an array ($image['url']) throws a warning or renders nothing when an editor has not set the image.
The fix is to guard the value before you use it, and only reach into array keys inside the guard:
$image = get_field( 'hero_image' );
if ( $image ) {
// Return Format = Array: safe to read keys here
echo '<img src="' . esc_url( $image['url'] ) . '" alt="' . esc_attr( $image['alt'] ) . '">';
}If you set the field to return a URL or an ID, guard the same way and use the scalar directly:
$image_url = get_field( 'hero_image' ); // Return Format = Image URL
if ( $image_url ) {
echo '<img src="' . esc_url( $image_url ) . '" alt="">';
}When an image field returns false and you are sure an image is set, it is the same three usual suspects from causes 1 and 2: the wrong field name (the name, not the label, and case-sensitive), the wrong post context or ID (in the loop versus outside it, or an options-page field that needs get_field( 'name', 'option' )), or a call that runs before ACF has initialized. Confirm the value with var_dump( get_field( 'hero_image', get_the_ID() ) ) first, then check the name and the post context before assuming the field type is the problem.
The diagnostic order
When get_field() is returning nothing in production code:
var_dump( get_field( 'your_field_name', get_the_ID() ) )to see what you actually get.- Confirm the field name is exactly right (case, underscores).
- Confirm the post ID is correct for the context.
- Confirm the field group's location rules match the post.
- Confirm the field group exists at all on this environment.
- If reading a sub-field, switch to
get_sub_field()insidehave_rows(). - If on a cached environment, flush the cache to rule out staleness.
- If you get back data but in an unexpected shape, check the return-format setting in the field group admin.
In my experience, causes 1, 2, and 3 cover roughly 70% of cases. Cause 5 (sub-field confusion) covers another 15%. The remaining 15% is spread across the others.
For AI-assisted debugging of this kind of issue (where the assistant reads the field group registration and your template code, then diagnoses the mismatch), see Using Claude CLI to Manage WordPress Sites.
Repeater first row empty
A Repeater where the first row comes out blank while rows 2 onward render is one of the more confusing ACF symptoms. It traces to one of three causes, plus a rare fourth.
Missing the_row() inside the loop. The loop needs the_row() as the first call inside while ( have_rows() ). Without it the row pointer never advances and get_sub_field() reads from no row at all:
// Broken: no the_row()
if ( have_rows( 'team_members' ) ) {
while ( have_rows( 'team_members' ) ) {
$name = get_sub_field( 'name' ); // always empty
}
}
// Correct
if ( have_rows( 'team_members' ) ) {
while ( have_rows( 'team_members' ) ) {
the_row();
$name = get_sub_field( 'name' );
$role = get_sub_field( 'role' );
echo '<li>' . esc_html( $name ) . ' (' . esc_html( $role ) . ')</li>';
}
}The tell: this makes every row empty, not just the first. If only row 1 is blank, look at the next cause.
A stray the_row() before the loop. This is the "specifically the first row" bug. Something outside the loop already consumed a row, so the while starts on row 2:
the_row( 'team_members' ); // advances the pointer outside the loop
if ( have_rows( 'team_members' ) ) {
while ( have_rows( 'team_members' ) ) {
the_row(); // now on row 2
echo get_sub_field( 'name' );
}
}Remove any the_row() call outside the canonical if ( have_rows() ) { while ( have_rows() ) { the_row(); ... } } pattern. Another loop earlier on the page over the same field can do the same thing.
update_field() overwrote the data. An acf/save_post hook, a WP-CLI migration or a form handler called update_field( 'team_members', $new_data, $post_id ) with an array that was missing the first row, mishandled the first index of $_POST data, or used sub-field keys that did not match the registration. Row 1 ends up empty or gone while the rest survive. Log the shape before every write (error_log( wp_json_encode( $new_data ) )) and the culprit is easy to find. Useful Things You Can Do with acf/save_post covers safe write patterns.
Rare: the stored count is out of sync. The Repeater's own meta row holds the row count, and ACF iterates on it. After an aborted bulk import it can disagree with the team_members_N_subfield rows. Compare them:
wp db query "SELECT meta_value FROM wp_postmeta WHERE post_id = 123 AND meta_key = 'team_members'"
wp db query "SELECT meta_key, meta_value FROM wp_postmeta WHERE post_id = 123 AND meta_key LIKE 'team_members_%'"If they disagree, re-save the post in the admin so ACF rewrites the meta consistently, or script a re-read, delete and clean update_field( 'team_members', $rows, $post_id ). I have seen this exactly twice, both after an aborted import, so rule out the first three causes first.
The quickest triage is var_dump( get_field( 'team_members', $post_id ) ). If row 1 is populated in the dump, the bug is in the template (a missing or stray the_row()). If row 1 is empty in the dump, the bug is in whatever wrote the data.
Count rows in an ACF Repeater
There are three ways to count Repeater rows, depending on where you are in the code.
count() on the field value, when you are about to use the rows anyway:
$rows = get_field( 'team_members', $post_id );
$count = is_array( $rows ) ? count( $rows ) : 0;The is_array check matters because get_field returns false for an empty Repeater, and count( false ) errors on PHP 8.x. Loading the field is the expensive step; counting it afterwards is free.
Row N of M inside a loop. ACF has no first-class get_field_count() helper. Count the field once before looping; the call hits ACF's internal cache rather than the database:
$total = 0;
if ( have_rows( 'team_members' ) ) {
$total = count( get_field( 'team_members' ) );
$index = 0;
while ( have_rows( 'team_members' ) ) {
the_row();
$index++;
printf( '<li>Item %d of %d: %s</li>',
$index, $total, esc_html( get_sub_field( 'name' ) )
);
}
}If you only need the position, get_row_index() returns the 1-based index of the current row, which is handy for first-row or alternate-row styling.
A direct meta read, when the count is all you need. The count is stored as a single meta value under the field's name:
$count = (int) get_post_meta( $post_id, 'team_members', true );That is one meta read instead of hydrating every row; on a Repeater with 200 rows and 5 sub-fields it skips 1,000+ reads. I use it on directory index pages that render 50 listings, each with a "view N events" link. The caveat is the same one behind the out-of-sync bug above: it is only right while the count meta matches the rows, which ACF maintains as long as you write through update_field, not update_post_meta.
Counting rows that match a condition has no meta shortcut; you iterate and test get_sub_field( 'is_active' ) on each row. On a hot path, store the result as a derived field on save instead:
add_action( 'acf/save_post', function ( $post_id ) {
$rows = get_field( 'team_members', $post_id ) ?: [];
$active = array_filter( $rows, fn( $r ) => ! empty( $r['is_active'] ) );
update_field( 'active_member_count', count( $active ), $post_id );
}, 20 );Across many posts, for reporting, use a WP-CLI command with the direct meta read rather than a page query:
WP_CLI::add_command( 'listing report-team-members', function () {
$total = 0;
$posts = get_posts( [
'post_type' => 'listing',
'posts_per_page' => -1,
'fields' => 'ids',
] );
foreach ( $posts as $post_id ) {
$total += (int) get_post_meta( $post_id, 'team_members', true );
}
WP_CLI::success( "Total team members across all listings: $total" );
} );On a site with 5,000 listings that runs in seconds rather than minutes. For more WP-CLI patterns that pair with ACF, see Using AI with WP-CLI for Faster WordPress Operations.
True/False field not working
A True/False field stores 1 (ticked) or 0 (unticked) in wp_postmeta. On a post that pre-dates the field the meta row does not exist and get_post_meta returns an empty string. get_field hydrates all of that to a real boolean: 1 becomes true, and 0, an empty string or missing meta become false. So if ( get_field( 'is_featured' ) ) is reliable. The bugs come from everything else.
Raw meta reads instead of get_field. get_post_meta returns strings ('1', '0' or ''), and PHP's string-to-boolean rules are easy to get wrong: (bool) '0' is false, but (bool) '0.0' is true. Mixing raw reads with loose comparisons (== 1) against hydrated values is the classic "True/False is not working" bug. Read the field with get_field and compare strictly (=== true) if you compare at all.
Legacy posts with no meta row. Add the field to a group that is already in use and existing posts have no value until they are saved, so get_field returns false for them. That is harmless if the field's default is false. If the default is true, new posts read true and old posts read false. Backfill once with WP-CLI:
WP_CLI::add_command( 'listing backfill-featured', function () {
$posts = get_posts( [ 'post_type' => 'listing', 'posts_per_page' => -1, 'fields' => 'ids' ] );
foreach ( $posts as $post_id ) {
if ( get_post_meta( $post_id, 'is_featured', true ) === '' ) {
update_field( 'is_featured', true, $post_id ); // or whatever default
}
}
WP_CLI::success( count( $posts ) . ' posts processed' );
} );The read-time alternative, get_post_meta( $post_id, 'is_featured', true ) === '' ? true : (bool) get_field( 'is_featured', $post_id ), works but is uglier. On long-lived sites this backfill gap is the most common True/False surprise I see.
Conditional logic keeps hidden values. Conditional rules fire on the editor's current state, and a field hidden by a toggle keeps its stored value, so get_field still returns it on the front end. Prefer positive rules over negated ones ("show when is_featured != true" works but reads awkwardly). If hidden should mean cleared, clear the dependants on save:
add_action( 'acf/save_post', function ( $post_id ) {
if ( ! get_field( 'is_featured', $post_id ) ) {
update_field( 'featured_image', null, $post_id );
update_field( 'featured_text', '', $post_id );
}
}, 20 );meta_query shape. meta_value is a text column, so compare against the string '1', not 1 or true. "False" has to include posts that never saved the field:
// true
'meta_query' => [
[ 'key' => 'is_featured', 'value' => '1' ],
],
// false or never saved
'meta_query' => [
'relation' => 'OR',
[ 'key' => 'is_featured', 'value' => '0' ],
[ 'key' => 'is_featured', 'compare' => 'NOT EXISTS' ],
],Writing it. update_field( 'is_featured', true, $post_id ) is the canonical form; 1, '1', false and 0 also work and ACF normalizes them to the stored 1 or 0. More write patterns are in How to Update ACF Fields Programmatically.
To triage, var_dump both get_field( 'is_featured', $post_id ) and get_post_meta( $post_id, 'is_featured', true ). An empty string from the second means the field was never saved on that post.
Select field default value
A Select field that comes back empty on older posts is often a default-value problem rather than a get_field problem.
The static default. In the field group editor, set "Default Value" to the option value, not the label (medium for an option medium : Medium). For a multi-select field, enter one value per line. ACF documents it as the value selected when the field is first edited: it pre-selects the option when the editor renders a new post, or an existing post with no saved value, and once the post is saved, the saved value wins. Do not count on it at read time. A post that never saved the field has no _priority reference row, so get_field( 'priority' ) cannot resolve the field by name, never sees its configured default and returns an empty value. Reading by field key (get_field( 'field_abc123' )) does fall back to the default, because ACF then knows the field; for name-based reads, use one of the options below.
Renamed options break it silently. Rename the medium option to mid-priority without updating the Default Value and the field shows with nothing selected. ACF throws no error.
Dynamic defaults with acf/load_value. For defaults that depend on runtime conditions, return a value from the filter when nothing is saved yet:
add_filter( 'acf/load_value/name=priority', function ( $value, $post_id, $field ) {
if ( ! empty( $value ) ) return $value;
// On a post that never saved the field, ACF passes a bare placeholder field
// with no choices, so load the real definition by name.
$choices = $field['choices'] ?? ( acf_get_field( 'priority' )['choices'] ?? array() );
$valid_choices = array_keys( $choices );
$default = 'high';
return in_array( $default, $valid_choices, true ) ? $default : '';
}, 10, 3 );The early return is essential: without it you overwrite saved values every time the post loads. Checking the field's choices also guards against the renamed-option problem. The filter can target name=priority, key=field_abc123 (safer when names collide) or type=select (every Select field on the site, rarely what you want). For a multi-select field, return an array such as ['blue', 'green']; a single string gets normalized to a one-item array, but arrays are cleaner.
The same filter covers the common dynamic cases. To inherit from a parent post:
add_filter( 'acf/load_value/name=industry', function ( $value, $post_id, $field ) {
if ( ! empty( $value ) ) return $value;
$parent_id = wp_get_post_parent_id( $post_id );
if ( $parent_id ) {
return get_field( 'industry', $parent_id );
}
return $value;
}, 10, 3 );And to default by the author's role:
add_filter( 'acf/load_value/name=visibility', function ( $value, $post_id, $field ) {
if ( ! empty( $value ) ) return $value;
$user = wp_get_current_user();
if ( in_array( 'subscriber', (array) $user->roles, true ) ) {
return 'private';
} elseif ( in_array( 'contributor', (array) $user->roles, true ) ) {
return 'pending-review';
}
return 'public';
}, 10, 3 );A guaranteed front-end fallback. If templates must never see an empty value regardless of how the default was set, wrap the read:
function te_get_priority_with_default( $post_id ) {
$value = get_field( 'priority', $post_id );
if ( empty( $value ) ) {
$value = 'high'; // your default logic
}
return $value;
}Or backfill the legacy posts once with a WP-CLI loop, the same pattern as the True/False backfill above.
Sources
Authoritative references this article was fact-checked against.
- get_field() function reference (Advanced Custom Fields docs)advancedcustomfields.com
- the_field() function reference (Advanced Custom Fields docs)advancedcustomfields.com
- Select field (Advanced Custom Fields docs)advancedcustomfields.com
- acf_get_value() and the default_value fallback (ACF source)github.com
- acf/load_value filter reference (Advanced Custom Fields docs)advancedcustomfields.com
- True/False field (Advanced Custom Fields docs)advancedcustomfields.com
- Boolean type (PHP manual)php.net
- Repeater field (Advanced Custom Fields docs)advancedcustomfields.com
- get_post_meta() function reference (WordPress Developer Resources)developer.wordpress.org
- have_rows() function reference (ACF docs)advancedcustomfields.com





