开发者

strtotime with variable in wordpress

开发者 https://www.devze.com 2023-03-12 09:18 出处:网络
I\'ve tried to change this code: function filter_where( $where = \'\' ) { $where .= \" AND post_date > \'\" . date(\'Y-m-d\', strtotime(\'-365 days\')) . \"\'\";

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', strto开发者_高级运维time('-'.$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.


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 and null.

Do you mean to pass that variable as an argument of and_where()?

0

精彩评论

暂无评论...
验证码 换一张
取 消