Advanced Custom Fields (ACF) for WordPress, here’s a simple example.

Example: Add an employee’s details

Suppose you have a WordPress Employee post type and want to add:

  • Employee Name
  • Job Title
  • Phone Number
  • Profile Photo

With ACF, you can create these as custom fields instead of putting everything into the normal WordPress editor.

1. Create an ACF Field Group

In WordPress:

ACF → Field Groups → Add New

Create a field group called Employee Details.

Add fields:

Field LabelField NameField Type
Employee Nameemployee_nameText
Job Titlejob_titleText
PhonephoneText
Profile Photoprofile_photoImage

Set the location to:

Post Type = Employee


2. Enter the data

When creating an employee:

Employee Name: Rahul Sharma
Job Title: Web Developer
Phone: 9876543210
Profile Photo: Rahul’s photo

ACF stores these values as custom fields associated with that WordPress post.


3. Display them in your WordPress theme

In your PHP template:

<h1><?php the_title(); ?></h1><p><strong>Name:</strong><?php echo esc_html(get_field('employee_name')); ?></p><p><strong>Job Title:</strong><?php echo esc_html(get_field('job_title')); ?></p><p><strong>Phone:</strong><?php echo esc_html(get_field('phone')); ?></p>

For the image:


$image=get_field('profile_photo');
?>
<img src="<?php echo $image['url']; ?>" height="100" width="100" alt="<?php echo $image['alt']; ?>" />
<?php

What ACF is doing

The basic flow is:

WordPress Admin → ACF Fields → Enter Data → Store with Post → get_field() → Display on Website

So instead of hard-coding:

<h2>Rahul Sharma</h2><p>Web Developer</p>

you make the content dynamic:

<h2><?phpechoesc_html(get_field('employee_name')); ?></h2><p><?phpechoesc_html(get_field('job_title')); ?></p>

This is especially useful for custom post types, websites with structured content, product details, team members, locations, portfolios, and directories.

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *