Support » Fixing WordPress » user meta and a user page loop

Viewing 9 replies - 1 through 9 (of 9 total)
  • ggarmento

    (@ggarmento)

    Here is my next run at the wall… I was PHP coding about five years ago, and this code syntax may show it.

    http://pastebin.com/FNCekLf6

    I was able to return data from the db wp_users table, and populate the HTML fields below, but the structure of the db wp_usermeta table is weird. So the table JOIN breaks at the following line.
    while ($usersarray = mysql_fetch_array($usersselect)) {

    any help would go a long way.

    If I understood you correctly you wanted a list of all the authors and editors, in which case you were looking at the wrong function.

    I think get_users is what you were looking for:

    <?php
    if ($editors = get_users( 'orderby=nicename&role=editor' )) {
        echo '<h4>Editors</h4>';
        echo '<ul>';
        foreach ($editors as $user) {
            echo '<li>' . $user->user_nicename . '</li>';
        }
        echo '</ul>';
    }
    
    if ($authors = get_users( 'orderby=nicename&role=author' )) {
        echo '<h4>Authors</h4>';
        echo '<ul>';
        foreach ($authors as $user) {
            echo '<li>' . $user->user_nicename . '</li>';
        }
        echo '</ul>';
    }
    ?>
    ggarmento

    (@ggarmento)

    the CODEX says that get_user function is depreciated.

    This code works, it runs a loop and delivers all users only once in teh return. http://pastebin.com/LwNw1CPs

    But it only returns half of the info (from the wp_users table); when I try to JOIN the wp_usermeta table it fails.

    Also, if anyone could stear me in the right direction so I can make good WP DB query requests I would appreciate it.

    ggarmento

    (@ggarmento)

    wow… I don’t know what I was looking at earlier.

    the CODEX says that get_user function is depreciated.

    i am goping with “lack of sleep” as an excuse. Thanks I will take tray again.

    ggarmento

    (@ggarmento)

    Thanks for your response Andrei.
    Okay that helped in a big way. That resolved my SORT and EXCLUDE issues. The only hurdle now is: getting the meta_values and the meta_keys using the get_users function. The SYNTAX on that part eludes me.
    http://pastebin.com/7MnmH2U4

    The CODEX looks light in that regard. Trying to ask the right question in the search field.

    You need to add fields parameter.

    $blogusers = get_users(array(
        'blog_id' => 1,
        'orderby' => 'blog_id',
        'exclude' => 1,
        'fields'  => 'all_with_meta'
    ));

    And then inside foreach add (to add the avatar)

    $user_avatar = get_avatar($user->ID, 32);
    echo '<a href="' . $user->user_url . '" target="_blank">' . $user_avatar . '</a>';

    the rest will work as it is now.

    ggarmento

    (@ggarmento)

    CheckMate!!! Andrei you are the smartest Norwegian I know.
    Your guidance and help is very much appreciated.
    http://www.chessgames.com/perl/chessgame?gid=1243022

    Hehe! Nice game 😉 and no problem, really.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘user meta and a user page loop’ is closed to new replies.