문제

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);
도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top