我想使用wpdb
我的外部页面上的类与wordpress没有关联。
我尝试在php文件中包含以下内容:
// include wordpress functions
include( $_SERVER[\'DOCUMENT_ROOT\'] . \'/wp-load.php\');
require_wp_db();
global $wpdb;
现在,我使用
$wpdb->query
$product_info_query = $wpdb->query("select p.products_id, p.products_type, p.img_display, p.products_sku, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_last_modified, p.products_date_available, p.manufacturers_id, gp.likes from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_GLOBAL_PRODUCTS . " gp where p.products_status = \'1\' and p.products_id = \'" . (int)$_GET[\'products_id\'] . "\' and pd.products_id = p.products_id and gp.products_id = p.products_id and pd.language_id = \'" . (int)$languages_id . "\'");
$product_info = mysql_fetch_array($product_info_query);
然而,它不起作用。它返回了一个警告:
Warning: mysql_fetch_array() expects parameter 1 to be resource
有什么问题吗?如何修复此问题以及可能使用
wpdb
在wordpress外部运行查询时是否正确初始化?