Performance: Advanced Custom Fields plugin
This affects page load speed and rendering by adding extra database queries and increasing HTML output size.
<?php if (have_rows('large_repeater_field')): while (have_rows('large_repeater_field')): the_row(); ?><?php the_sub_field('small_field'); ?><?php endwhile; endif; ?>
<?php the_field('large_repeater_field'); ?>| Pattern | Database Queries | HTML Size | Load Time Impact | Verdict |
|---|---|---|---|---|
| Loading large repeater fields fully | High (many queries) | Large (+50kb) | Slows LCP by 200-400ms | [X] Bad |
| Loading only needed subfields with conditionals | Moderate (fewer queries) | Smaller (+10-20kb) | Improves LCP by 150-300ms | [OK] Good |
subtitle using ACF in a WordPress template?get_field() returns the value of a custom field.the_field() echoes the value, not returns it; others are invalid functions.$subtitle = get_field('subtitle');
if ($subtitle) {
echo "$subtitle
";
} else {
echo "No subtitle found
";
}subtitle is empty or not set?$subtitle has a value. If empty or not set, condition is false.echo get_field('price');if (get_field('price')) to ensure value exists before output.name, role, and photo. Which approach correctly uses ACF to loop through a repeater field called team_members and display each member's info?have_rows() and the_row() to loop through rows.get_sub_field() inside the loop to get each subfield value.Pass the test and this pattern moves unknown