Title: What does this code do?
Last modified: August 19, 2016

---

# What does this code do?

 *  Resolved [sharecommons](https://wordpress.org/support/users/sharecommons/)
 * (@sharecommons)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/what-does-this-code-do/)
 * Hello guys,
 * I’m trying to understand what this code does:
 *     ```
       <?php
                       $authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts);
                       if($authors):
                       foreach($authors as $author):
       ?>
       ```
   
 * Would appreciate if you guys can explain it line by line.
    Thanks a lot.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/what-does-this-code-do/#post-1643250)
 * Here is an interpretation of the code:
 *     ```
       get an array of author ids from the posts table
       if there are any author ids
         loop through the author ids array one author id at a time
       ```
   
 *  Thread Starter [sharecommons](https://wordpress.org/support/users/sharecommons/)
 * (@sharecommons)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/what-does-this-code-do/#post-1643367)
 * Hello vtxyzzy,
 * Thank you for the reply. Would it be possible for you to help me with this thread:
   [http://wordpress.org/support/topic/templating-authorphp](http://wordpress.org/support/topic/templating-authorphp)
 * I have this code in my author.php file and I’m trying to create some query to
   work out my author.php file. As you can see, I’m not that good with coding but
   trying to learn. Interacting with database is a little out of my understanding.
   Please help if you can.
 * Appreciate your help, thank you.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 9 months ago](https://wordpress.org/support/topic/what-does-this-code-do/#post-1643445)
 * Check your other thread.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘What does this code do?’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [Coding](https://wordpress.org/support/topic-tag/coding/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [15 years, 9 months ago](https://wordpress.org/support/topic/what-does-this-code-do/#post-1643445)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
