在wordpress中带有变量的strtotime [英] strtotime with variable in wordpress
本文介绍了在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 函数中?
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.
推荐答案
这是正确的代码 if $timestamp
包含一个正整数.
It is the correct code if $timestamp
contains a positive integer.
然而,在没有global
关键字的函数上下文中,$timestamp
未定义且null
.
However, in the context of that function and without the global
keyword, $timestamp
is undefined and null
.
您的意思是将该变量作为 and_where()
的参数传递吗?
Do you mean to pass that variable as an argument of and_where()
?
这篇关于在wordpress中带有变量的strtotime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文