If you want show a custom field from a user profile in your template, add this snippet to your functions.php, custom functionality plugin, or to a snippet manager like Code Snippets or Advanced Scripts.
Note: This is written specifically for ACF (using the get_field helper function), but you can use the same function for fields created with Meta Box or any other custom field plugin. Just swap
get_field
for whatever helper function your plugin uses. (For example, the function is rwmb_meta
for Meta Box.)<?php /** * Returns the value of supplied field for the current logged in user. * @param string $field_name Name of the custom field created using ACF. * @return string Value of user field. */ function ob_get_user_custom_field( $field_name ) { return get_field( $field_name, 'user_' . get_current_user_id() ); } ?>
To show the field value on the frontend use the function
ob_get_user_custom_field( $field_name )
, then replace $field_name
with the name of your custom meta.