• 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)
  • If your table is in your WordPress database just use 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.