android - 如何使用 REST API 检索 woocommerce 产品数据?
问题描述
我正在使用 api php 获取 woocommerce 产品数据,但它无法正常工作。
请在下面找到代码。
任何帮助,将不胜感激。
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
//Checking if any error occured while connecting
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
//creating a query
$stmt = $conn->prepare("SELECT p.ID,p.post_title,p.post_status,p.post_name,pp.min_price,pp.max_price,
pi.meta_value FROM `wp_posts` p INNER JOIN `wp_wc_product_meta_lookup` pp ON pp.product_id = p.ID
INNER JOIN `wp_postmeta` pi ON pi.post_id=p.ID where p.post_status='publish' and pi.meta_key ='_wp_attached_file'
and `p.post_type`='product'GROUP BY p.ID;");
//executing the query
$stmt->execute();
//binding results to the query
$stmt->bind_result($post_id,$post_title, $post_status, $post_name,$min_price, $max_price , $meta_value);
$courses = array();
//traversing through all the result
while($stmt->fetch()){
$temp = array();
$temp['post_id'] = $post_id;
$temp['post_title'] = $post_title;
$temp['post_status'] = $post_status;
$temp['post_name'] = $post_name;
$temp['min_price'] = $min_price;
$temp['max_price'] = $max_price;
$temp['meta_value'] = $meta_value;
array_push($courses, $temp);
}
//echo count($courses);
//displaying the result in json format
echo json_encode($courses);
解决方案
推荐阅读
- vb.net - Datatable.Select() 无法过滤包含“#”的值
- python - python文件处理格式
- php - WooCommerce - 如何检查当前端点和子端点?
- android - 未完成交互时如何关闭按钮可见性
- python - 嗨,我在使用中断功能时遇到错误
- server - 仍然在服务器上收到消息(imapd)从 xxx.xxx.xxx.xxx(CID/国家/-)的 IMAP 登录失败,即使我已经从任何软件中注销
- html - 如何在上传文件(primeng)之前要求确认?
- c - 使用 callgrind 或程序集修改优化嵌套 if 和 switch 语句
- node.js - Express 静态网络请求停留在“未决”状态
- python - Python KeyError:'destinationAccount'