Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress wpdb undefined variable

Tags:

wordpress

I'm writing a plugin and trying to request some data from a custom table in my database using:

$current_text = $wpdb->get_results("SELECT text FROM addtext ORDER BY id DESC LIMIT 1");

but just get the error Undefined variable: wpdb

Any idea why this isn't working? I've followed the docs and scoured Google, with no luck. Still pretty new to WP plugins so probably something obvious.

Thanks!

like image 301
logic-unit Avatar asked Feb 01 '11 16:02

logic-unit


1 Answers

I needed to use global $wpdb; in my function.

like image 85
logic-unit Avatar answered Nov 16 '22 02:11

logic-unit