Using Custom Field on the Frontend

Learn to display the value of a custom field on the frontend.

The values of a custom field are stored as post_meta when the post is stored. To access post_meta values, WordPress has a function get_post_meta(). However, since we are using the Advanced Custom Fields plugin, we have access to a function named get_field(). This function is superior to the native WordPress function as it handles the formatting depending upon the field type. The get_field() function fetches the value in a variable while a similar the_field() function displays the custom field’s value.

These functions take the field name as argument and return the value of the field.

To find the field name, go to the "ACF" option in the admin sidebar. Every field group lists the labels, names and types of the fields.

The get_field() function

To display the custom fields, we can edit any template file. Let’s start with single-teacher.php.

The code for the banner area is reproduced below:

Get hands-on with 1200+ tech skills courses.