我正在使用这段代码...
<ul>
<?php
$args = array(
'posts_per_page' => 10,
'orderby' => 'post_date',
'order' => 'DESC',
'post_status' => 'publish, trash'
);
$query = new WP_Query( $args ); ?>
<?php while ($query -> have_posts()) : $query -> the_post();
?>
<li>
<?php the_title(); ?>
<br />Post Created on: <?php echo get_the_date(); ?>
<br />Post Trashed on: <?php echo "???"; ?>
</li>
<?php
endwhile;
wp_reset_postdata();
?>
</ul>
。以显示最近 10 个已发布或已丢弃的帖子的列表。
但是,对于返回的已删除帖子,它们必须是帖子被丢弃的日期,而不是创建时间。
为了进一步说明这个问题,如果一年多前有一些帖子,而我今天把它们扔掉了,它们不会出现在这个列表中,因为它们不在数据库中最近的 10 个帖子之列。
需要发生的是,如果我现在确实删除了一个非常旧的帖子,那么它就会出现在这个列表中(实际上是在列表的顶部 - 因为我刚才扔掉了它(。
因此,此列表最终需要反映的是:
- 添加的任何新帖子,显示帖子的创建日期。 任何被丢弃的帖子
- ,显示帖子被丢弃的日期。
把它想象成一个活动日志(最终就是这样(,显示最近创建的帖子和最近被丢弃的帖子的组合,旁边有它们各自的发布和删除日期。
提前谢谢。
使用'orderby' => 'modified'
,当您删除帖子时,它会更改修改日期,您也可以使用echo get_the_modified_date()
显示它
或使用get_posts()
$args = array(
'posts_per_page' => 10,
'orderby' => 'modified',
'order' => 'DESC',
'post_status' => 'publish, trash'
);
$query = new WP_Query( $args );
$posts = $query->get_posts();
foreach ( $posts as $post ) {
_e($post->post_title ' - Modified On:'. $post->post_modified);
}