WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a code Example:

function custom_func(){
    global $wpdb;
    $wpdb->flush();     //tried with and without this line
    $getTest = 'SELECT * FROM $wpdb->wp_users LIMIT 1';
    $arrayReturned = $wpdb->get_results($wpdb->prepare($getTest));

From what I've read I thought that $wpdb->wp_users is meant to have returned the database name and table name like so dbName.tableName; but it just returns an empty value.

I've tried:

$getTest = 'SELECT * FROM $wpdb->wp_users LIMIT 1';

which shows as the following to wordpress:

SELECT * FROM $wpdb->wp_users LIMIT 1


$getTest = 'SELECT * FROM '.$wpdb->wp_users.' LIMIT 1';

which shows as the following to wordpress:


I can't fathom why this isn't working since this is all based on literature from the wordpress codex, any thoughts?

share|improve this question
up vote 0 down vote accepted

First of all why you would need custom query for this basic functionality to get users, when WordPress has inbuilt function get_users().

Anyway for custom query, table name is defined as

function custom_func(){
 global $wpdb;
 $getTest = "SELECT * FROM $wpdb->users LIMIT 1";
 $arrayReturned = $wpdb->get_results($wpdb->prepare($getTest));

It's $wpdb->users or $wpdb->post and not $wpdb->wp_users, what you use for a table name, in custom queries.

Also I've used the double quotes " " for query and not single quotes ' ', you can read here

share|improve this answer
This was just a test example based on what I was reading, but you fixed all of the problems I was having with the table name changes, thanks. – VikingGoat Mar 26 '14 at 17:17
Hope you could commit to community too :) – sven Mar 26 '14 at 20:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.