Support

Account

Home Forums General Issues Display Name and role using a user field Reply To: Display Name and role using a user field

  • I should have encapsulated the damn thing in <pre>...</pre>. Would have been much easier to read.
    Now, the dump says that this should, in fact, have been the solution. But if the roles still do not show up, I must have overlooked something. Please try the following and, when you censor the sensitive data, take care to not paint over any brackets. Those are important.

    <h3>Asistentes</h3>
    <div>
    <?php $users = get_field('asistentes'); ?>
    <!--<ul>-->
    <?php
    foreach ($users as $user):
    $roles = new WP_User( $user['ID'] ) ?? false ;
    echo '<pre>';
    var_dump( $user , $roles );
    $roles = is_object( $roles ) ? $roles->roles : [] ;
    var_dump( $roles );
    echo '</pre>';
    ?>
    <li>
    	<p><?php echo $user['display_name'];
    	echo 'User roles: ' . implode(', ', $roles) . "\n";?></p>
    </li>
    <?php endforeach; ?>
    </div>