我试图通过如下显示的日期自定义字段显示邮政订单:
Year
Month
Custom field post info(date, time, venue, and category)
Title
我在论坛中找到了这个功能,并对其进行了一些修改,可以很好地按年份、月份和日期进行分类和显示,但现在我已经整理好了帖子,我想添加每篇文章的标题和信息的其余部分,所以我需要的是一种在foreach statemets中显示这些信息的方法,或者是一个有序帖子ID的数组(我认为这个选项对我来说更容易)<?php
$posts = get_posts(array(
\'post_type\' => \'post\',
\'meta_key\' => \'fecha\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
\'meta_type\' => \'DATE\'
));
$group_posts = array();
if( $posts ) {
foreach( $posts as $post ) {
$date = CFS()->get( \'fecha\' );
$date = new DateTime($date);
$year = $date->format(\'Y\');
$month = $date->format(\'F\');
$group_posts[$year][$month][] = array($post, $date);
}
}
foreach ($group_posts as $yearKey => $years) {
echo $yearKey;
echo \'<br>\';
foreach ($years as $monthKey => $months) {
echo $monthKey;
echo \'<br>\';
foreach ($months as $postKey => $posts) {
echo $posts[1]->format(\'d-m-Y\');
echo \'<br>\';
echo $posts[0]->title;
echo \'<br>\';
}
}
}
?>
任何帮助都将不胜感激!