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
and
$getTest = 'SELECT * FROM '.$wpdb->wp_users.' LIMIT 1';
which shows as the following to wordpress:
SELECT * FROM LIMIT 1
I can’t fathom why this isn’t working since this is all based on literature from the wordpress codex, any thoughts?
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
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