Search code examples
phphtmlwordpressadvanced-custom-fields

Wordpress Frontend user field with HTML


I was wondering if someone could please help me clean up how this displays on the fronted, I use this to display a directory of users that are entered in a ACF field on some posts. Each field will have multiple users. I would like to have a bullet point for each user followed by their info and then each email address to be a mailto link.

<?php
$users = get_field('pds_construction_coordinators', '');
echo "<ul>";
foreach($users as $user){
    $user_id = $user['ID'];
    $user_email = $user['user_email'];
    $user_display_name = $user['display_name'];
    $user_company = get_field('company_name', 'user_'.$user_id);
    $user_phone = get_field('phone_number', 'user_'.$user_id);


    echo "<li> $user_company, $user_display_name, <a href="mailto:<?php echo ($user_email); ?>"><?php echo $user_email; ?></a>, $user_phone </li>";

    echo "<br />";
}
echo "</ul>";

Solution

  • Below is what ended up working for me, not the cleanest, but it works:

    <?php
    $users = get_field('pds_construction_coordinators', '');
    echo "<ul>";
    foreach($users as $user){
    
    $user_id = $user['ID'];
    $user_email = $user['user_email'];
    $user_display_name = $user['display_name'];
    $user_company = get_field('company_name', 'user_'.$user_id);
    $user_phone = get_field('phone_number', 'user_'.$user_id);
    
    echo "<li>";
    echo "<strong>$user_company</strong> <br/>";
    echo "$user_display_name <br/>";
    echo "$user_phone <br/>";
    echo "<a href='mailto:$user_email'>$user_email</a><br/>";
    echo "</li>";
    }
    echo "<ul>";