1

I'm using following code to display my users on template

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$paged -= 1;
$limit = 100;
$offset = $paged * $limit;

$args  = array(
    'number' => $limit,
    'offset' => $offset,
    'role'         => 'editor',
);

global $wp_query;
$wp_query = new WP_User_Query($args);

// Get the results
$authors = $wp_query->get_results();


 foreach($authors as $author) : 

     echo $author->description; 

  endforeach;

?>

Which works perfectly fine, however I would like to also display custom fields which I have created by using plugin Advanced Custom Fields. I have managed to do that on author.php page with this code:

$author_id2 = get_the_author_meta( 'ID' );
$author_badge = get_field('profile_picture', 'user_'. $author_id2 ); // image field, return type = "Image Object"

<img src="<?php echo $author_badge; ?>" alt="<?php echo $author_badge['alt']; ?>" class="alignright" /> 

But I'm not sure how to display the same field in my WP_User_Query. Any tips will be much appreciated

1

As I know or at the moment of the last time I checked, ACF doesn't meta-data in their "best" location, as in get_term_meta, or meta data for users.

Instead of that, Elliot did a very strange thing, but focusing in what you're asking for:

get_field('your-field','user_' . $author->ID);

So the loop you will have to add something like above, check out more in his tutorial: http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-user/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.