1

I used this tutorial so that I would have the ability to associate categories with users. However, I changed the code so that it would show only on Subscribers profiles (not Authors like in the tutorial).

What I would like to do now is create a custom page template which shows a list of Subscribers including their avatar, first name, last name, email address and all the categories associated with that user.

This is the code I have so far, but I don't know how to call the array of categories associated with each user:

// Create the WP_User_Query object
$wp_user_query = new WP_User_Query(array (
    'role' => 'Subscriber',
    'order' => 'ASC',
    'orderby' => 'display_name'
));

// Get the results
$subscribers = $wp_user_query->get_results();

// Looping subscribers
if (!empty($subscribers)) {
    foreach ($subscribers as $subscriber)
    {
        // get all the user's data
        $user_info = get_userdata($subscriber->ID); 

        //printing basic infos
        echo '<div style="width:290; float:left; margin-right:20px;">';
        echo '<div>';
        echo get_avatar( get_the_author_meta( $subscriber->ID ), 290 );
        echo '</div>';
        echo '<div>';
        echo ''.$user_info->first_name.' '.$user_info->last_name.'';
        echo '</br><a href="mailto:'.$user_info->user_email.'">'.$user_info->user_email.'</a>';
        echo '</br>'.$user_info->description.'';
        echo '</div>';
        echo '</div>';
    }
} else {
    echo 'No Subscribers found';
}

Any help would be greatly appreciated.

0

Wasn't sure how the categories were being associated with the users so I checked the tutorial you linked to and found this:

$user_meta = get_user_meta( $user_id, USER_CATEGORY_META_KEY, true );

It'd be whatever your code's version of that line is... so whatever you're saving the categories as in terms of user_meta, you'd call that. But change the true to false so you get all of them instead of just one. From there you should be able to parse all of it however you want.

| improve this answer | |

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.