Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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);
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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);
share|improve this answer
    
That was it. Thanks! –  Scott B Nov 10 '10 at 17:39
    
@Scott B - Can't tell you how often I've been stuck on that very issue... :) –  MikeSchinkel Nov 10 '10 at 18:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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