'" . date('Ym...">

Strtotime with variable in wordpress

I tried changing this code:

function filter_where( $where = '' ) { $where .= " AND post_date > '" . date('Ym-d', strtotime('-365 days')) . "'"; return $where;} add_filter( 'posts_where', 'filter_where' ); 

in that:

 function filter_where( $where = '' ) { $where .= " AND post_date > '" . date('Ym-d', strtotime('-'.$timestamp.' days')) ."'"; return $where;} add_filter( 'posts_where', 'filter_where' ); 

You may notice that I tried to put the $ timestamp variable inside strtotime. However, the code does not work. I made the correct syntax to put a variable in the strtotime PHP function?

I appreciate any help.

0
source share
1 answer

This is the correct code if $timestamp contains a positive integer.

However , in the context of this function and without the global $timestamp keyword, there are undefined and null .

Do you want to pass this variable as an argument to and_where() ?

0
source

Source: https://habr.com/ru/post/1386364/


All Articles