1

我想检索子类别中的所有产品。这是我的代码:

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 个产品。

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

4

1 回答 1

1
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),它将显示最多 100000000 的所有记录。

使用 MySQL LIMIT 和 OFFSET 查询选择所有记录

于 2016-08-01T06:42:24.680 回答