问题
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