A
A
Alexander Plyusnin2021-08-12 22:57:53
WordPress
Alexander Plyusnin, 2021-08-12 22:57:53

How to display metafields on the author's page if a certain role is assigned to him?

Good day. Can you please tell me how to display certain meta fields on the author's page if the author has been assigned a certain role? And how not to display if it's just a member? The participant is registered. He has a personal account, he fills in the fields, then he is assigned a role and the fields are displayed in the frontend.

I found the if( is_user_role( 'custom_role' ) ) construct, but there is a lot of html and I'm new to PHP and I don't really understand how to display it. Through echo or something else? Would it be correct to output the html container with such a condition?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-08-13
@bioWeb

if ( is_user_role( 'custom_role' ) ) {
  echo '<p>' . get_user_meta( get_current_user_id(), 'custom_meta', true )  . '</p>';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question