Forums

Listing users, but only some of them (4 posts)

  1. YorkshireLad
    Member
    Posted 3 years ago #

    Hi,

    I'm trying to add a comple of template files that will allow me to produce a list of some (but not all) of the users on my site. The idea is that there will be a three-column list of players, with photos nd their position (achieved by using the AIM field, so I don't have to add a custom field); choosing a player will take the user to a page with a bigger picture, description, and any recent blog posts.

    The second part of this seems to be working fine, but getting the list of users is a lot harder!

    If I use Kaf's code (http://guff.szub.net/source/page-authors.php), then the result is a blank page. Adding $wpdb->show_errors(); at the top tells me that it fails because I'm sorting on a non-existent column. So I looked at http://codex.wordpress.org/Author_Templates, which has some user information fields, but these don't work either; I can sort the list by ID or display_name, but nothing else seems to work.

    I'm reasonably sure that I understand how to exclude certain users (based on the ID), but how do I build my list of users, sorted by lastname? If I can't do the sort, the list isn't going to be much use.

    Gary

  2. YorkshireLad
    Member
    Posted 3 years ago #

    No ideas or pointers?

    Gary

  3. YorkshireLad
    Member
    Posted 3 years ago #

    Okay. After a bit of delving in the depths of Codex, I found some code samples. Stringing them together like this:

    <h2>Author Profiles:</h2>

    <?php $user_count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users;"); ?>
    <p><?php echo 'There are ' . $user_count . ' first- and reserve-team players at the club.'; ?></p>

    <?php $fivesdrafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'published' AND post_author = 6");

    foreach ($fivesdrafts as $fivesdraft) {
    echo $fivesdraft->post_title;
    } ?>

    <?php $usercount2 = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY ID"); ?>
    <p><?php echo $usercount2; ?></p>

    <?php foreach ($usercount2 as $userA) : ?>
    <?php echo $userA; ?>
    <?php $user_info = get_userdata($userA); echo($user_info->last_name . ", " . $user_info->first_name . "\n"); ?>
    <?php endforeach; ?>

    produces the following:

    Author Profiles:
    There are 16 first- and reserve-team players at the club.

    Array

    Object , Object , Object , Object , Object , Object , Object , Object , Object , Object , Object , Object , Object , Object , Object , Object ,

    Close, but no banana. What might I be doing wrong? This file is in mt template directory (with the rest of the templates).
    Gary

  4. talgalili
    Member
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic