The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] Undefined variable: wpdb (3 posts)

  1. robdunne
    Posted 5 years ago #


    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 follow the docs and scoured Google, with no luck. Still pretty new to WP plugins so probably something obvious.


  2. robdunne
    Posted 5 years ago #

    This is a plugin, and not outside of wordpress so I shouldn't need to include any other files.

    No idea why this doesn't work.

    Any ideas?

  3. robdunne
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic