Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

First of all, I have a custom function in functions.php that gets some author information. This works on great on single posts with a single author.

<?php function the_author_box() { ?>
<div class="widget about-the-author-widget">        
    <h3 class="widget-title">Over de auteur</h3>
    <div class="author-header clear">
        <div class="author-avatar-wrap"><?php echo get_avatar(get_the_author_meta( 'ID' )); ?></div>
        <h4 class="author-name"><?php the_author_meta('display_name'); ?></h4>
    </div>
    <div class="author-description"><p><?php the_author_meta('description'); ?></p></div>
    <ul class="author-meta">
        <?php if ( get_the_author_meta( 'url' ) ) { ?>
            <li class="url">
                <a href="<?php the_author_meta( 'url' ); ?>" title="De website van <?php the_author_meta( 'display_name' ); ?>">Website</a>
            </li>
            <?php // a lot more metas ?>
    </ul>
</div>
    <?php
} ?>

But now I'm designing a custom page template to display the 'the_author_box' for every user who is either a contributor or an administrator. All on the same page.

I figured I could get the users by doing so (borrowed from stackexchange). Build a new function:

function get_clients() { 

    $users = array();
    $roles = array('author', 'contributor', 'administrator');

    foreach ($roles as $role) :
        $users_query = new WP_User_Query( array( 
            'fields' => 'all_with_meta', 
            'role' => $role, 
            'orderby' => 'display_name'
            ) );
        $results = $users_query->get_results();
        if ($results) $users = array_merge($users, $results);
    endforeach;

    return $users;
}

Call the users, and execute the function for every user:

<?php
$users_array = get_clients();
foreach ($users_array as $user) {
$user->the_author_box();
?>

But that doesn't work. I am guessing because it's still 'the author meta' that's called, and not the user's meta.

How can I call a function for $user->function(). In other words, how can I get meta information from that user?

share|improve this question
add comment

1 Answer

First, always var_dump() something if you aren't sure what exactly you got. If you ain't got XDebug installed and configured, just use

printf( '<pre>%s</pre>', htmlspecialchars( var_export( $dumpMe, true ) ) );

which will bring up an equally informative response.

About the WP_User_Query) IIRC it returns objects which are instances of WP_User. You can test that with

$user instanceof WP_User AND print 'Yes, I am a WP_User object';

If that is the case, simply use

var_dump( get_user_meta( $user->user_id ) );

and you should be fine. Btw, there's no real Author Meta.

share|improve this answer
    
Could you elaborate a little on what this var_dump does? And how would I implement this? –  Bram Vanroy Sep 17 '13 at 14:11
1  
Search Google for XDebug and var_dump, as well as print_r and var_export. –  kaiser Sep 17 '13 at 14:11
    
Well that's a disappointing answer. –  Bram Vanroy Sep 17 '13 at 14:44
1  
@BramVanroy How would one comment explain such broad (and basic PHP) topics better than extensive search results from Google? Answers here serve a purpose of helping you further, not answering each and every question you got in mind. Especially if it barely touches the WordPress-topic. –  kaiser Sep 17 '13 at 14:52
    
True, and I definitely will Google all those terms, but it doesn't answer my original question. "I have tried this, but it doesn't work. Maybe this is the problem. How do I make this work?" So, an answer would also cover how I should implement this. I don't need the explanation of everyting (it's useful though, but I can google one thing and another) but I need to know how to implement it. –  Bram Vanroy Sep 17 '13 at 16:07
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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