【问题标题】:WooCommerce-mysql - get list of products in a categoryWooCommerce-mysql - 获取类别中的产品列表
【发布时间】:2016-12-04 21:32:30
【问题描述】:

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

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

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

【问题讨论】:

    标签: php woocommerce woocommerce-rest-api


    【解决方案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 接受开始和结束值。

    如果您提供Limit 5,它将仅显示前 5 条记录。 如果您提供Limit 5,10,它将显示 5-10 之间的记录。 如果你给 Limit 0, big number (eg. Limit 0,100000000) 它将显示所有记录到 100000000。

    Select all records using MySQL LIMIT and OFFSET query

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-09
      • 2014-06-27
      • 1970-01-01
      • 1970-01-01
      • 2015-05-27
      • 2014-01-27
      • 2021-08-05
      • 1970-01-01
      相关资源
      最近更新 更多