Enhance WordPress wp_list_authors Template Tag

2 min read

Enhance WordPress wp_list_authors Template Tag

2 min read

As can be seen by some of the comments left on the site, a couple of frequently requested features cannot be added to the List Authors widget because they are not supported by the underlying wp_list_authors template tag. The WordPress code for wp_list_authors needs to be changed to enable these new features.

Feature 1: Allow an upper limit to the number of authors listed. Some WordPress sites have hundreds or even thousands of contributors. wp_list_authors currently would list all of them and, worse, execute an SQL statement for each author. The proposed fix could be a non-negative integer option named “count_limit.”

Feature 2: Allow sorting of the author list. This could be an option named “sort_by” with the values “name” and “post_count.”

Today I submitted a patch to WordPress Trac including both of the above features. It also changes the code to use a JOIN statement to get the author post count instead of running an SQL statement for every author. This was a necessity to prevent inconsistencies when applying the LIMIT and ORDER BY. One of the core developers is reviewing it now and, if I’m lucky, the change will be included in the next major release (version 3.0). If that happens, you can be sure I will be updating the List Authors widget to make use of the new options.

A less frequent request but one I’ve seen is for an “exclude” option with the ability to filter out certain categories of authors. There is a separate ticket for this and I might consider submitting a patch for this next.

6 Comments

  • FlossieT March 24, 2010 at 4:53 pm

    @Takaitra
    Absolutely – it was just what I was looking for, and I’ve also used it to improve a sidebar plugin. Now I just need to figure out how to patch your sorting even further to randomise the listing of authors…

  • FlossieT February 25, 2010 at 6:55 am

    @FlossieT
    Ignore me – figured it out. Doh! FANTASTIC stuff. Exactly what I needed.

    • Takaitra February 25, 2010 at 10:14 pm

      Great, I’m glad you were able to apply the patch.

  • FlossieT February 25, 2010 at 6:48 am

    This is really excellent work – thank you. This is probably not the place to ask for support but – I’m completely new to the WP Trac system! I’m running 2.9.2 – what’s the best way to apply your patch?

  • Takaitra January 17, 2010 at 8:04 pm

    @Sam Burdge
    Hi Sam,
    I forgot to mention it in my post, but the patch I submitted for the wp_list_authors template tag does indeed streamline the SQL so that only one query is performed instead of one for each author. There is an open enhancement request in WordPress Trac regarding this subject and from which I got some hints on how to write the correct JOIN statements. As you can see, that request is two years old! We can only hope that the wp_list_authors patch is included in WordPress 3.0 and then at least one template tag will be streamlined.

  • Sam Burdge January 17, 2010 at 11:07 am

    Hi Takaitra
    Your suggestion to improve this function is a great idea. The fact that it has to make one db query per author at the moment means that this one function alone can double or even triple the number of sql queries per page load.

    WordPress used to store the ‘user_status’ in the wp_users table, so this function could be performed on a single db query. Wouldn’t that approach be better? as for a simple call of the function it would eliminate the need to make multiple queries to the user_meta table.

    In my opinion a main priority for WordPress should be to streamline a lot of its template tags to be less greedy with the number of sql queries. For busy sites with high traffic the extra queries can cause the mysql memory to max out, even when using a caching plugin.

  • Leave a Reply

    ×