WordPressWordPressACFAdvanced Custom FieldsPluginPHP

Advanced Custom Fields (ACF) Tutorial: Custom Data for WordPress

Master Advanced Custom Fields (ACF) to add custom data fields to WordPress posts, pages, and custom post types — without writing PHP.

Abdur Razzak

Abdur Razzak

Full-Stack Web Developer

July 19, 2025 10 min read

What Is ACF and Why Use It?

Advanced Custom Fields (ACF) lets you add structured custom data fields to WordPress content without writing custom PHP code. Need to add a 'project URL', 'client name', and 'completion date' to your portfolio posts? ACF lets you create these fields through the admin interface and displays them on posts automatically. It is the most popular WordPress plugin for custom data management with over 2 million active installations.

Creating Field Groups

In the ACF admin panel, create a Field Group — a collection of related fields that appear together on the editing screen. Set the location rules to determine where the group appears: on specific post types, specific pages, user profiles, or taxonomy terms. Add fields of various types: Text, Textarea, Image, File, Select, Checkbox, Relationship, Repeater, and Flexible Content.

Displaying ACF Data in Templates

In your theme template files, retrieve field values with the_field('field_name') to output the value directly, or get_field('field_name') to retrieve it as a PHP variable. For image fields, get_field() returns an array with url, width, height, and alt. For relationship fields, it returns an array of WP_Post objects. Use these in your template's HTML to display the custom data.

Repeater Fields for Dynamic Content

The Repeater field (ACF Pro) lets editors add a variable number of rows, each containing sub-fields. Perfect for testimonials, team members, pricing tiers, or FAQ items — content with a variable number of entries. Loop through repeater rows with have_rows() and the_row() functions. Each row's sub-fields are accessed with get_sub_field('field_name').

Flexible Content for Layout Building

The Flexible Content field (ACF Pro) lets editors build custom page layouts by adding and ordering content blocks — hero section, feature grid, testimonials, CTA — in any combination. Each layout is a template partial in your theme. This gives editors page-builder flexibility with developer-defined, design-constrained templates. It is a powerful alternative to full page builders for teams that want editorial flexibility without visual bloat.

ACF and the WordPress REST API

ACF data is not included in the WordPress REST API by default. Install the ACF to REST API plugin or add a custom field registration in your theme's functions.php using register_rest_field(). This exposes your ACF fields in the REST API response, enabling headless WordPress setups where a React or Next.js frontend consumes WordPress data including custom fields.

Share this article

All posts
#WordPress#ACF#Advanced Custom Fields#Plugin#PHP
Abdur Razzak — Full Stack Web Developer

Full-Stack Expert

MERN · React · Next.js · WordPress