我连接到db并成功地提取了产品数据。现在我想展示特定类别的产品。这家商店正在使用woocommerce。登录页位于不同的位置,因此我无法导入wp函数。
以下是我目前的想法:
SELECT ID, `post_date` , `post_title` , `post_content` , `guid` FROM `wp_posts` as post
INNER JOIN wp_term_relationships rs ON rs.object_id = post.ID
INNER JOIN wp_terms t ON t.term_id = rs.term_taxonomy_id
WHERE `post_type` = "product"
AND `post_status` = "publish"
AND rs.term_taxonomy_id = 117
ORDER BY post_date DESC LIMIT 5
什么都没发生。如果我删除
AND rs.term_taxonomy_id = 117
它像以前一样工作。5最旧的产品出现。不是特定类别的产品。我错过了什么?
SO网友:ksr89
我检查了您的查询,它工作正常,没有任何错误或空结果。但除此之外,如果您删除INNER JOIN
从…起wp_terms
表也可以工作,因为您没有从该表中获得任何东西,并且它没有在中使用WHERE
第条也是。
SELECT ID, `post_date` , `post_title` , `post_content` , `guid` FROM `wp_posts` as post
INNER JOIN wp_term_relationships rs ON rs.object_id = post.ID
WHERE `post_type` = "post" //post type post for my example
AND `post_status` = "publish"
AND rs.term_taxonomy_id = 1 //term_taxanomy_id is 1 for my example
ORDER BY post_date DESC LIMIT 5