How to display special custom filed on the post for special role?

How to display special custom filed on the post for special role?

I have two custom fields on the post? Can I display custom fields for different role in the front-end?

Hey Steve,

Firstly, please check this KB article to see how to display an ACF field value on the site:

Now, to only display the field value to a certain rule, you will have to get the user role of the current user then user an if statement.

Please install and activate the child theme and login through FTP then edit the functions.php then add this code:

 * Get the user's roles
function get_current_user_role() {
  if( is_user_logged_in() ) {
      $user = wp_get_current_user();
      $roles = ( array ) $user->roles;
      return $roles[0];
  } else {
      return '';

The code above is a function that will return the user role that is currently logged in on the site so you just have to call the function get_current_user_role anywhere in the child theme.

So in the template file, you will have something like:

    if( get_current_user_role() == 'administrator') :
        echo the_field('about_author');

So the field about_author will only be displayed if the logged in user is an administrator.

Here is a link for reference about the Wordpress user roles.

If you have custom roles, please user the role slug in the theme files.

This should help you get started and if you are not certain how to proceed, you might want to consider getting in touch with a developer as further customization from this goes beyond the scope of support.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.