• Hi everyone,

    I just need a little bit of help with an if else to show a custom field I have created to users based on their user role.

    If they are a certain user role, or even a certain user role and/or higher i was this to show

    <p>MAP: <?php the_field(‘map’); ?></p>

    I can’t seem to figure it out after looking around all day.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The codex has a comprehensive page on roles and capabilities. Roles and Capabilities page

    Long story short though, you’re probably looking to use the current_user_can() function. Pass it a role name, capability name, or an array of either, and you’ll receive boolean answers. Good luck!

    Thread Starter orbetllc

    (@orbetllc)

    Are you able to help me with this? I can’t seem to figure it out properly.

    what have you tried? If you show your code, maybe I can point out where things have gone wrong ??

    Thread Starter orbetllc

    (@orbetllc)

    if( is_super_admin() ):
        echo the_field('msrp');
    else:
        echo '';
    endif;
    ?>
    
    		<?php
    if( is_super_admin() ):
        echo the_field('map');
    else:
        echo '';
    endif;

    Are you sure you’re a network admin? Super Admins are only used in multisite installations. In a “normal” WP installation, you probably want to target the Administrator user instead with is_admin()

    Thread Starter orbetllc

    (@orbetllc)

    Yes it works, I just don’t know how I would implement (using s2member) level 2 member and above, or something or the sort

    Thread Starter orbetllc

    (@orbetllc)

    or even just one level would be fine too

    This sounds like you should be asking in their support forum for that, then ?? https://www.ads-software.com/support/plugin/s2member

    Or try and see if the current_user_can() function I mentioned above will work with their roles: I don’t know since I haven’t played with their framework. Good luck!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Show field based on user role (if else)’ is closed to new replies.