![](/img/trans.png)
[英]WordPress get_terms() function not display custom taxonomy categories for woocommerce
[英]get_terms ignores orderby argument on WooCommerce product categories
我使用以下功能列出產品類別並按名稱排序。 自從我上次將 WooCommerce 從 3.5.7 更新到 3.6.1 以來,這不再起作用了。
沒關系,我寫什么到orderby
。 我猜這些術語按 id 排序,與后端的順序相同。
我以前遇到過這個問題,但后來我添加了'menu_order' => false
並且它起作用了。 但自從更新后,什么都不起作用了。
$terms = get_terms( 'product_cat', array(
'orderby' => 'name',
'order' => 'ASC',
'parent' => 2063,
'menu_order' => false,
'suppress_filter' => false
) );
我也嘗試切換主題沒有成功。 歡迎任何幫助。
我使用 WordPress 5.1.1 版和 Storefront 主題 2.4.5 版。
更新 2 - 已解決
在我在 Github WooCommerce 上報告了這個問題后,這顯然是調用
get_terms()
函數時影響orderby
參數的錯誤。 現在已經批准並修補了。該問題已在 Woocommerce 更新 3.6.2 上解決
首先,因為 WordPress 4.5 分類法應該通過get_terms()
函數的參數數組中的“分類法”參數傳遞。
您不能使用'menu_order'
和'suppress_filter'
參數,因為它們不是為WP_Term_Query
類定義的。 您將使用'orderby' => 'order',
代替'menu_order'
。
現在WP_Term_Query
__construct()
中列出了 WordPress get_terms()
函數允許的參數。
所以是的,你可以使用 **" orderby
"參數:**
name
。name
, slug
, term_group
, term_id
, id
, description
, parent
), count
的術語分類計數, include
匹配order
的$包括PARAM的, slug__in
匹配order
的$塞PARAM的, meta_value
, meta_value_num
, $meta_key 的值, $meta_query 的數組鍵,或none
以省略 ORDER BY 子句。所以你的代碼應該是這樣的:
$terms = get_terms( 'product_cat', array(
'taxonomy' => 'product_cat',
// 'orderby' => 'name', // <=== Default orderby is already 'name'
'order' => 'ASC',
'parent' => 2063,
) );
測試和
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.