[英]How can i get all post of taxonomy category post by taxonomy category id or taxonomy category name in wordPress?
[英]Sort Category/taxonomy based on post count in wordpress
有沒有辦法根據它包含的帖子數量對類別/分類列表進行排序?
問候,Desizner
<?php
foreach (get_categories('orderby=count&order=DESC') as $category )
{
/*Some stuff here*/
}
?>
有關詳細信息,請查看: https : //developer.wordpress.org/reference/functions/get_categories/
目前(2017年9月)我也使用wp_list_categories (作為Ryan B),但使用以下代碼:
<?php wp_list_categories( array(
'orderby' => 'count',
'order' => 'DESC'
) ); ?>
你可以使用get_categories()函數並在'taxonomy'中傳遞其中一個值:'category'(僅獲取類別)或'post_tag'(僅獲取標簽),甚至刪除此鍵,它將同時獲得。 貝婁我們按照每個類別DESC的帖子進行排序。
<?php
$categories = get_categories([
'taxonomy' => 'category',
'orderby' => 'count',
'order' => 'DESC'
]);
foreach ($categories as $category) {
// Do something
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.