【问题标题】:filter post_where using minutes使用分钟过滤 post_where
【发布时间】:2013-09-13 09:28:52
【问题描述】:

我正在使用需要按特定日期范围过滤的 wordpress WP_Query 循环。

因此,我设置了以下过滤器以显示超过 10 天的所有帖子:

//Create a filter that only shows posts for a certain time frame
function restrict_posts_by_date_10( $where = '' ) {
    global $wpdb;

    $where .= " AND post_date <= '" . date('Y-m-d', strtotime('-10 days')) . "'";

    return $where;
}

add_filter( 'posts_where', 'restrict_posts_by_date_10' );

出于测试目的,我不能等待几天才能触发其余的动作,所以我想将其设置为 2 分钟。但是,以下不起作用

//Create a filter that only shows posts for a certain time frame
function restrict_posts_by_date_10( $where = '' ) {
    global $wpdb;

    $where .= " AND post_date <= '" . date('Y-m-d', strtotime('-2 minutes')) . "'";

    return $where;
}

add_filter( 'posts_where', 'restrict_posts_by_date_10' );

任何想法都会很棒。

干杯

【问题讨论】:

    标签: wordpress filter


    【解决方案1】:

    strtotime() 是一个 PHP 函数,您可以在此处阅读:

    http://php.net/manual/en/function.strtotime.php

    根据手册,您可以简单地使用字符串“now”进行测试,或者如果您愿意,可以使用“+2 分钟”。我找不到任何证据表明该函数采用负整数。恐怕我没有时间测试这些建议,但应该很容易尝试。

    【讨论】:

      猜你喜欢
      • 2018-07-16
      • 2016-04-22
      • 2020-01-28
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 2011-07-15
      相关资源
      最近更新 更多