I am new to the wordpress and want to create a plugin but $wpdb is not initiating, I am using wordpress version 4.9.4

Here is my code snippet

global $wpdp;
$sql    = 'SELECT * From '.$wpdp->prefix.' my_first_plugin';
$result = $wpdp->get_results($sql); 
  • 1
    Where is this code? (in which hook/filter) Did you check for errors? (your SQL query is invalid)
    – kero
    Feb 14 '18 at 10:38

You have written $wpdb incorrectly (3x) in your code example. If it is an exact copy it will never work. And you have a space in your SQL after prefix.' which shouldn't be there. And 'From' shoul dbe all caps.

Try this:

global $wpdb;
$sql    = 'SELECT * FROM ' . $wpdb->prefix . 'my_first_plugin';
$result = $wpdb->get_results($sql); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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