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