Condition depending on certain author / user role (on pages)

Hi, I’d like to only show certain elements on a page/post if the author has or doesn’t have a certain role. For example, I want certain sections to no longer be displayed when the author’s user role is switched from Author to Contributor. How is the condition to be coded?

Follow-up question: Is there a complete list of all available / usable codes for dynamic content somewhere?

Hello Daryl,

Thanks for writing in! WordPress established Roles where users can create/edit/publish post items and also access to different parts of the dashboard. The Roles is divided into levels and capabilities which then added as a user meta. To check if it is an Author or Contributor, you can use the dynamic content access the user meta {{dc:user:meta key="wp_user_level"}} and {{dc:user:meta key="wp_capabilities"}}.

Regretfully we do not have a complete list of the dynamic content. I will raise this as a request to put up a list as an enhancement to or documentation.

Best Regards.

1 Like

Many thanks. However, the codes {{dc:user:meta key=“wp_user_level”}} and {{dc:user:meta key=“wp_capabilities”}} do not work for me (no output). I then found the same tags in the list of possible user meta information for authors, but obviously with the name of the database instead of “wp_”. The name could be different for anybody e.g. like {{dc:author:meta key=“74Jd73_user_level”}}. Using these codes I can read the values - but database name must not change then. Can you confirm that the codes with “wp_…” should work instead?

Regarding the list of dynamic content: I would appreciate it very much if there was a clear, searchable list here. I have often found forum replies with dynamic content codes here and I thought “Oh, interesting! You can read and use that?”. Examples of the structure of query strings and the possible concatenating of conditions would also be great for such documentation. e.g. how does: “IF {{dc:user:meta key=“wp_user_level”}} IN 1,2 AND {{dc:user:meta key=“wp_capabilities”}} > 8” ?

Hey Daryl,

The condition should be:
{{dc:user:meta key="wp_user_level"}} > 8 AND {{dc:user:meta key="wp_capabilities"}} <= 2

If in your case, the post meta key is 74Jd73_user_level then it could be because I am using the default WordPress table prefix which is just wp_.

Kindly let us know how it goes.

Thanks for the code.
Can I find descriptions anywhere how to concatenate conditions? If I want to use descriptions like “is in 1,5,6, 9” or others?

Regarding database prefix: Ok, I understand.

Hi Daryl,

You will use String condition and IN as your operator for the expression while wrapping the group of numbers in an array:

Hope this makes sense.

Ok, I thank you!

Hi Daryl,

You are most welcome.

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