如何编辑一个函数来显示在未来几天内到期的帖子


How to edit a function to show posts that are expiring in the next days?

下面的代码显示了最近30天内发布的帖子。
例如,我有一个名为expiring的meta_key, meta_value为2011-10-22

在我的情况下,我想删除post_date并找到哪些职位即将过期。例如,今天我们有2011-10-18,我想显示从今天(18)到2011-10-21的所有帖子。也就是3天后。

明天2011-10-19必须显示可能在2011-10-22过期的帖子。

这就是我如何获得meta_key get_post_meta($post->ID, 'expiring', true);的值

这是我尝试编辑的函数。

<?php
function filter_where($where = '') {
    //posts in the last 30 days
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
    return $where;
}
add_filter('posts_where', 'filter_where');
query_posts('post_type=post&posts_per_page=10&order=DESC');
while (have_posts()): the_post(); ?>
<li><?php the_title(); ?></li>
<?php
endwhile;
wp_reset_query();
?>

谢谢你的帮助。

我不知道我是否正确理解这个问题,但似乎你想在你的功能中有这个:

$where .= " AND expire_date < '" . date('Y-m-d', strtotime('+3 days')) . "'";

按expire_date排序,而不是post date,并取过期日期不迟于未来3天的所有内容