Support » Plugin: ACF: User Role Selector » Create array of roles selected

  • Resolved John

    (@jemoreto)


    Hello guys!

    I know this is a very simple question, but I’m not able to know how to create an array of user roles selected.

    I’m using the User Role field for been chosen in a page.
    With this values I’ll allow current user to see the page content.

    Here is my code:

    // Store the ACF "Role" info
    $roles = get_field('iuser_role');

    if($roles) {
    // Create an array of users that will be able to access the page from the ACF "User" field
    $roles_that_can_access_this_post = array();
    foreach($roles as $role) {
    $roles_IDs_that_can_access_this_post[] = $role;
    }

    Thanks!!

    https://wordpress.org/plugins/acf-role-selector-field/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author danielpataki

    (@danielpataki)

    Hi John,

    I just had to restore my computer so I don’t have any test servers running. However, you can definitely select what you want returned in the options. If you set it to objects you’ll get an array of objects, if you set it to names, you’ll get an array of role names.

    Either way, if you use var_dump( $roles ) just after you’ve retrieved the value of the field you should see what the variable contains making this a lot easier 🙂

    Daniel

    Thread Starter John

    (@jemoreto)

    Thanks, man!
    I got it! Solved.

    Cheers!

    Plugin Author danielpataki

    (@danielpataki)

    Awesome! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Create array of roles selected’ is closed to new replies.