Advanced Custom Fields (Loop user profile field)

I have created a field within the wordpress profile (created with a plugin called Advanced Custom Fields) which allows customers to upload their logo. I would like to now loop through all those customers and display that logo (in a list preferably)

Here are some attempts, can someone guide me to the right direction:

Read More
<?php
    $args = get_users( array( 'fields' => array( 'display_name' ) ) );
    $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post();
            echo '<li>';
            echo '<img src="';
            the_field('company_logo');
            echo '" alt="';
            the_field('company_name');
            echo '"/>';
            echo '</li>';
        endwhile;

Here is another attempt

        <?php
            $blogusers = get_users( array( 'fields' => array( 'display_name' ) ) );

            $variable = get_field('company_logo', $blogusers);

            foreach ( $blogusers as $user ) {
                echo the_field('company_logo', $blodusers);
            }

        ?>

Another

<?php
    $blogusers = get_users('orderby=company_name');
    $author_id = get_the_author_meta( 'ID' );
    $image1 = get_field('company_logo', 'user_'. $author_id );
        $image2 = get_field('company_name', 'user_'. $author_id );

    foreach ($blogusers as $author_id) {
            echo '<li><div class="image_wrapper"><img class="profile1" src="';
            echo $image1['url'];
            echo '"/></div><img class="profile2 hoverShow" src="';
            echo $image2['url'];
            echo '"/><div class="imageOverlay"><p>';
            echo '</p></div></li>';

    }
?>

None of the above are showing any results apart from the HTML echos’

Thanks in advance

Related posts

Leave a Reply

1 comment

  1. You need to call get_field for each user within your loop.

    Something like this:

    <?php
        $blogusers = get_users();
    
        foreach ($blogusers as $user) {
    
                $author_id = $user->ID;
    
                $image1 = get_field('company_logo', 'user_'. $author_id );
                $image2 = get_field('company_name', 'user_'. $author_id );
    
                echo '<li><div class="image_wrapper"><img class="profile1" src="';
                echo $image1['url'];
                echo '"/></div><img class="profile2 hoverShow" src="';
                echo $image2['url'];
                echo '"/><div class="imageOverlay"><p>';
                echo '</p></div></li>';
    
        }
    ?>
    

    Note: i’m not sure what the data is actually like for your company_logo and company_name fields.. sounds kinda weird that company_name should return an image..

    Edit: If you want to sort by company_name, you’ll need to do something like this (Note this isn’t tested)

    $blogusers = get_users(array( 'meta_key' => 'company_name', 'orderby'=>'meta_value' ));
    

    Check the doc for more details http://codex.wordpress.org/Class_Reference/WP_User_Query