• First I would like to say I am very new to php, so please take it easy on me.

    I’m first going to explain what I am trying to do in hopes that this explains to you what I did with this code and why it does not work for me.

    I have been asked to build a guild website (gaming) for an upcoming Massively multi-player online game (Star Wars the old Republic). With that said we have a need for a members page, that lists these key items:

    • Character Name
      Character level
      Class
      Profession
      etc.
    • I found an example on how to list member names (character names) like this in a table:

      <?php
      $blogusers = get_users('blog_id=1&orderby=nicename');
      foreach ($blogusers as $user) {
      echo '<li>' . $user->user_nicename . '</li>';
      }
      ?>

      I then found a tutorial on how to add custom user fields to the profile page and save them to user_meta. This was great. the problem I am having is that I created a field for “class” but it seems the only way to display this information is to use get_meta_data which requires me to enter a user_id which only returns one class. I then found a few examples that I put together (not 100% sure how this works) and came up with the following:

      <?php
      $query = "SELECT ID FROM {$wpdb->users}";
      $user_ids = $wpdb->get_col($query, 0);
      $key = 'class';
      $single = true;
      $user_char_name = get_user_meta( $user_ids, $key, $single );
      foreach ($user_ids as $user_ID){
      echo '<li>' . $user_char_name . '</li>';}
      ?>

      The only problem with this is that it returns the class of the first user_id for everybody.

      Here is a link to the wesbsite so you can see what it is doing.

      http://usparadoxum.net/?page_id=74

      I need it to return the class depending on what was typed and saved in the custom profile field box.

      Example:

      Character 1 : Bounty Hunter
      Character 2: Imperial Agent
      Character 3: Sith Warrior
      character 4: Sith Inquisitor

      Depending on which one they type in the box and save, is the one I want to display in the list being populated to a table. As of right now user_id 1 is a Bounty Hunter and in each line of the list for every member I get the class of Bounty Hunter.

      If you have any questions please feel free to ask.

      Thanks in advance.

Viewing 1 replies (of 1 total)
  • Thread Starter vudujoose

    (@vudujoose)

    Topic solved figured it out, thanks for anyone who was thinking of answering =P

    For purposes of learning I will show how I did it though…

    <?php
    $szSort = "user_nicename";
    $aUsersID = $wpdb->get_col( $wpdb->prepare(
    "SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC", $szSort ));
    foreach ( $aUsersID as $iUserID ) :
    $key = 'class';
    $single = true;
    $user = get_userdata( $iUserID, $key );
    echo '
    <li>' . ucwords( strtolower( $user->$key ) ) . '</li>
    ';
    endforeach;
    ?>
Viewing 1 replies (of 1 total)

The topic ‘Getting multiple user_id …’ is closed to new replies.