I am trying to use the argument of the first function as a variable in the second function and this is how I got it to work so far, but I doubt it is the good way. Note that the second function (clauseWhere) can not have other arguments.
function filtrerDuree($time) {
global $theTime;
$theTime = $time;
function clauseWhere($where = '') {
global $theTime;
return $where .= " AND post_date > '" . date('Y-m-d', strtotime('-' . $theTime. ' days')) . "'";
}
add_filter( 'posts_where', 'clauseWhere' );
}
I could not use the argument $time directly in the second function like this: strtotime('-' . $time. ' days')), because it is local to the first function anyway.
Putting global $time in the second function did not work, even if I did $time=$time in the first function.
Also, I don't understand why I need to put global on $theTime in the first function...this variable does not exist outside the function, so it's not using any variable outside the function. If I don't put it global, it does not work. I do understand, though, that in the second function I need to put it global.