0

In the code below (from my functions.php), I'm attempting to create an array of items from the wp_postmeta table where the meta_key is "_wp_attached_file". I'm getting an error:

Fatal error: Call to a member function query() on a non-object

What's wrong with the query?

$excludeImages = array();
$excludeImages = $wpdb->query("SELECT meta_value 
                              FROM $wpdb->postmeta 
                              WHERE meta_key = '_wp_attached_file'");

array_push($excludeImages);

1 Answer 1

4

Hi @Scott B:

Did you remember to include a global $wpdb; in your code, like so?

global $wpdb;
$excludeImages = array();
$excludeImages = $wpdb->query("SELECT meta_value 
                              FROM $wpdb->postmeta 
                              WHERE meta_key = '_wp_attached_file'");

array_push($excludeImages);
1
  • @Scott B - Can't tell you how often I've been stuck on that very issue... :) Nov 10, 2010 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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