strtotime with variable in wordpress

核能气质少年 提交于 2019-12-24 20:27:23

问题


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.


回答1:


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()?



来源:https://stackoverflow.com/questions/6301213/strtotime-with-variable-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!