帖子和条款-订单

时间:2019-04-05 10:11:05

标签: wordpress posts taxonomy-terms

我有自定义分类法(类别)

2019 (level 1, term_id: 20)
   • January (level 2, term_id: 28)
         • Sport (level 3, term_id: 17)
         • Music (level 3, term_id: 14)
   • February (level 2, term_id:15)
         • Sport (level 3, term_id:29)
         • Music (level 3, term_id:64)
   • March (level 2, term_id:22)
         • Sport (level 3, term_id:33)
         • Music (level 3, term_id:37)

问题是,如何按分类顺序日期

对帖子进行排序

因此,首先是体育(一月)中的帖子-按日期排序,然后是音乐(一月)-按日期排序的帖子,然后是体育(二月) -按日期排序-依此类推

$timeline = new WP_Query(array(
'post_type' => 'news_posts',
'post_status' => 'publish',
'orderby' => array('menu_order' => 'ASC', 'date' => 'DESC'),
'ignore_sticky_posts' => true,
'posts_per_page' => -1,
'no_found_rows' => true
));

foreach ($timeline->posts as $post){
echo $post->post_title;
echo '<br>';
}

0 个答案:

没有答案