WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] List authors function mysteriously not working

[Resolved] List authors function mysteriously not working

  • I recently upgraded a site I manage, allthingsplc.info/wordpress, to WP3.1. Everything worked except the “wp_list_authors” function, which seems to break no matter where I put it. Right now I want to use it here:

    http://www.allthingsplc.info/wordpress/archives-author.php

    The original code for the page is here:

    http://stikked.com/view/14405892

    I’ve tried disabling plugins already, if anyone has other ideas for why it’s not working they’d be much appreciated. This is so strange – other functions like wp_list_categories work like a charm.

    If I can’t get it fixed – can someone tell me how I could just access to the user database and list the authors with their links without using the built-in wordpress function wp_list_authors?

    Thank you!!!

Viewing 15 replies - 1 through 15 (of 27 total)
  • im not sure why this isnt working.. but i can tell you how to get a list of the authors..

    get the user ID’s of all authors (wp_user_level = 2)

    $author_IDs = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='wp_user_level' AND meta_value='2'");

    get all users to compare to

    $users = $wpdb->get_col("SELECT ID FROM $wpdb->users");

    compare

    for($j=0; $j < count($author_IDs); $j++){
        if(in_array($author_IDs,$users){
          echo $author_IDs[$j];
        }
      }

    not the most elegant coding.. but hey 😛

    You’re the best!!!! I think you might have just saved me. I’ll try this and let you know if it works.

    The way this one function won’t work is pretty weird, right? I wish I had even a vague idea of why it’s not working.

    i havent seen it mentioned as an issue with 3.1 although i dont suppose people use that function much..

    it appears to still be on the 3.1 function list so it hasnt been depreciated.. in fact they added functionality to it by allowing orderby and number

    http://codex.wordpress.org/Function_Reference/wp_list_authors

    Sorry to be a bit of an idiot, but I tried using the code and now I’m getting a blank page: http://www.allthingsplc.info/wordpress/archives-author.php

    I have a basic understanding of what you’re doing but I’m not sure I know where the problem is here – also, if I want to print these author names in li tags, where would I put that?

    ok if ever you are getting a blank page like that it means there is a php error.. so i may have typed something wrong if you jsut copy pasted..

    to check if thats the case.. pop

    error_reporting(E_ALL);
    ini_set('display_errors', '1');

    at the top of the archive page and it should tell you if you have made a call to an unknown function or something..

    i can actually see where i have gone wrong.. let me ammend my code and ill comment where to add list items around the names the section you want to edit is in the comparison loop:

    $author_IDs = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='wp_user_level' AND meta_value='2'");
    $users = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users");
    for($j=0; $j < count($users); $j++){
        if(in_array($users[$j][ID],$author_IDs){
          //things before the username
          echo $users[$j][user_login];
          //things after the username
        }
      }

    now if you wanted them to be list items youd want to replace my comments with

    echo "<li>";

    and

    echo "</li>";

    respectfully

    sorry for the mess up

    i also forgot that you were going to want the users username not just their ID..

    Ah, I’m sorry, I tried the new code and it still doesn’t seem to be working. Not sure what I’m doing wrong…but I want to say that I really greatly appreciate you helping with this!

    I tried using that function to get error messages but nothing came up.

    Can you tell me where exactly I should put it? I tried literally at the top of the page, like so:

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    ?>

    but that didn’t seem to work.

    oh WOW im silly

    im sorry… here this IS THE CORRECT CODE!! (i not only forgot my closing bracket i also forgot that multi dimentional arrays dont get accessed like that in PHP )

    $author_IDs = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='wp_user_level' AND meta_value='2'");
    $users = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users"); ?>
    <ul>
    <?php
    for($j=0; $j < count($users); $j++){
        if(in_array($users[$j]->ID,$author_IDs0){
          //things before the username
          echo "<li>".$users[$j]->user_login."</li>";
          //things after the username
        }
      }
    ?>
    </ul>

    as a sorry again i put it in a list for you…

    my bad

    should there be a <?php at the beginning there?

    yes.. its 1am in Australia.. im sorry

    Hey, please don’t apologize you’re being wonderfully kind and helping me! I really appreciate it. It’s actually still not working but I’ll keep messing with it. I just need to teach myself how all these php/wp functions work and remind myself what a for loop is…

    oh for the love of god.. i typed a 0 instead of a close bracket…

    <?php
    $author_IDs = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key='wp_user_level' AND meta_value='2'");
    $users = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users"); ?>
    <ul>
    <?php
    for($j=0; $j < count($users); $j++){
        if(in_array($users[$j]->ID,$author_IDs)){
          //things before the username
          echo "<li>".$users[$j]->user_login."</li>";
          //things after the username
        }
      }
    ?>
    </ul>

    i have tested this on my own server and it works ok for me 🙁

    oh and delete that error checking thing from the top of the page now too…

    This is so exciting! The page now displays but the stuff inside the ul tags isn’t getting shown.

    Hm.

    are the people that you say are ‘authors’ actually set to be ‘Author’ in their user role?

    by this i mean.. under your users section of the dashboard.. click ‘edit’ on any of the users you want to show and check that their role is set to Author..

    if you want a list of people from a different role let me know and ill make the changes

    Aha…what I really want to show is anybody who has written a post…

    So I’m thinking, I could access all post_authors != 0 from the posts table, and display those names in a list…and then I’d have to compare the user ID to the user table to get the user_url.

    Or, I could only list those users with the user type of “contributor” AND “admin”…that’s the easy route but could cause problems when a contributor hasn’t yet written a post.

    I want to add in links to each of the author pages but I think I can figure out how to do that.

    Again – I really appreciate your help!

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘[Resolved] List authors function mysteriously not working’ is closed to new replies.
Skip to toolbar