Title: Database call in template
Last modified: August 19, 2016

---

# Database call in template

 *  [ShMk](https://wordpress.org/support/users/shmk/)
 * (@shmk)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/database-call-in-template/)
 * I have in my template a dropdown box that has to retrieve datas from a custome
   made table in the database.
 * What is the right method to do this?
 * I could directly execute a “SELECT” query on my database from my template file?
   
   I have to create a function somewhere else and then call it from the template?
 * Please explain me how to do that 🙂

Viewing 1 replies (of 1 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/database-call-in-template/#post-1347996)
 * If your table is in your WordPress database just use [wpdb](http://codex.wordpress.org/wpdb)
   in the actual template. Or put the function in your theme’s functions.php–for
   example:
 *     ```
       function countusers() {
       global $wpdb;
       $user_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->users;"));
       echo '<p>User count is ' . $user_count . '</p>';
       }
       ```
   
 * And then in your theme’s template file just use `countusers();`

Viewing 1 replies (of 1 total)

The topic ‘Database call in template’ is closed to new replies.

 * 1 reply
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/database-call-in-template/#post-1347996)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
