wordpress 中带有变量的 strtotime
我尝试将
function filter_where( $where = '' ) {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-365 days')) . "'";
return $where;}
add_filter( 'posts_where', 'filter_where' );
以下代码更改为:
function filter_where( $where = '' ) {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-'.$timestamp.' days')) ."'";
return $where;}
add_filter( 'posts_where', 'filter_where' );
您可能会注意到我尝试将变量 $timestamp 放入 strtotime 中。但是该代码不起作用。我是否使用了正确的语法将变量放入 strtotime PHP 函数中?
我很感激任何形式的帮助。
I've tried to change this code:
function filter_where( $where = '' ) {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-365 days')) . "'";
return $where;}
add_filter( 'posts_where', 'filter_where' );
into this one:
function filter_where( $where = '' ) {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-'.$timestamp.' days')) ."'";
return $where;}
add_filter( 'posts_where', 'filter_where' );
You may noticed that I've tried to put variable $timestamp inside strtotime. However the code doesn't work. Did I do the correct syntax to put the variable within the strtotime PHP function?
I appreciate any kind of help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
$timestamp
包含正整数,则它是正确的代码。但是,在该函数的上下文中并且没有
global
关键字,$timestamp
未定义且null
。您的意思是将该变量作为
and_where()
的参数传递吗?It is the correct code if
$timestamp
contains a positive integer.However, in the context of that function and without the
global
keyword,$timestamp
is undefined andnull
.Do you mean to pass that variable as an argument of
and_where()
?