2016-07-30 101 views
0

我想检索一个子类别中的所有产品。这是我的代码:WooCommerce-mysql - 获取产品的类别列表

SELECT * from `wp_term_relationships` where term_taxonomy_id=$subcatId and 
object_id in(select ID from `wp_posts` where `post_type`='product' and post_status='publish' and ID=wp_term_relationships.object_id) 

的问题是,约20级的产品验证码回报,但是当我去到该类别的网站,它返回约40个产品。

你能帮我吗?我需要一个代码来返回一个类别内的产品列表。

回答

0
SELECT * from `wp_term_relationships` where term_taxonomy_id=$subcatId and object_id in(select ID from `wp_posts` where `post_type`='product' and post_status='publish' and ID=wp_term_relationships.object_id) LIMIT 0,15000000 

在你的mysql查询中使用Limit关键字。

限制接受开始和结束值。

如果您给Limit 5它将只显示前5条记录。 如果您给Limit 5,10它将显示5-10之间的记录。 如果你是给限制0大的数字(如Limit 0,100000000),它会显示所有的记录高达1亿。

Select all records using MySQL LIMIT and OFFSET query

相关问题