【发布时间】:2015-07-23 13:16:53
【问题描述】:
我必须从 woocommerce 表中检索产品详细信息,例如图片标题、描述、图片链接和价格。
我已使用此查询检索到类别,
$result = mysql_query("SELECT term_id,name,slug FROM wp_terms WHERE term_id
IN (SELECT term_id FROM wp_term_taxonomy WHERE parent='0'
AND taxonomy='product_cat') ORDER BY name ASC");
基于此类别 ID,我正在检索这样的子类别:
$result = mysql_query("SELECT term_id,name,slug FROM wp_terms WHERE term_id
IN (SELECT term_id FROM wp_term_taxonomy WHERE parent='$cat_id'
AND taxonomy='product_cat') ORDER BY name ASC");
我已尝试查询以获取产品详细信息,
$result = mysql_query("SELECT `ID`,`post_title`,`post_content`,`guid` FROM wp_posts WHERE
post_type='product' and post_status='publish' and ID IN(SELECT object_id
FROM wp_term_relationships WHERE term_taxonomy_id IN('$cat_id') and
term_taxonomy_id IN(SELECT term_taxonomy_id FROM wp_term_taxonomy
where taxonomy='product_cat'))");
当我在phpmyadmin 中执行它时,这给了我标题和描述,但是当我在 php 中给出相同的代码并通过json 发送响应时,它给了我一个空响应。
我认为我的查询不正确。
请建议我如何从 woocommerce 获取产品详细信息,我是第一次使用它。
【问题讨论】:
-
这不会返回多个产品吗?你到底想做什么?你不应该为此需要任何 SQL...
-
是的。我需要一份产品清单。连同它的详细信息。我通过
json将响应发送到我的 android 应用程序并在移动设备中显示这些项目
标签: php mysql wordpress woocommerce