WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Author role conditional check (7 posts)

  1. clarklab
    Member
    Posted 4 years ago #

    On the post page I'm looking for a way to add an author bio for users only with the role 'contributor'

    This closest thing I've found was this and a few others posts but they were all geared towards comment authors.

    we have a few writers (admins, editors) that post all the time and on those posts we don't need the author bio so a conditional to check the role would be perfect. any ideas?

  2. CallUp
    Member
    Posted 4 years ago #

    You can do something like this:

    <?php global $user_level;

    <!--get_currentuserinfo() gets the currentuser info and automatically assigns the values to some global variables, including $user_level, above-->
    get_currentuserinfo();
    if ($user_level == 1) { ?><!--user level 1 equates to 'contributor'-->
    <!--here's where you could put your bio link-->
    <?php } ?>

    Hope this helps.

  3. CallUp
    Member
    Posted 4 years ago #

  4. clarklab
    Member
    Posted 4 years ago #

    that works but it seems to check the role of the logged in user, not the author of the post.

  5. clarklab
    Member
    Posted 4 years ago #

    Ah I figured it out. This works just fine:

    <?php $var = get_the_author_meta('user_level');
    if ($var == 1) {
    the_author_link();
    }?>
  6. CallUp
    Member
    Posted 4 years ago #

  7. CallUp
    Member
    Posted 4 years ago #

    OOps, I posted before I saw yours. :)

Topic Closed

This topic has been closed to new replies.

About this Topic