And So I have these:

echo ('timeframe1:');echo ($timeframe);

function filter_where($where = '') {
echo ('timeframe2:');echo ($timeframe);
$where .= " AND post_date > '" . date('Y-m-d', strtotime("-$timeframe days")) . "'";
return $where;
}

echo ('timeframe3:');echo ($timeframe);

Derive from individuals codes above are:

timeframe1: 5
timeframe2:
timeframe3: 5

Real question is, ways to get my $time-frame value within the function? As you can tell, the end result from echoing the $time-frame within the function is null. How obtain the predefined $time-frame worth of 5 within the function?

use GLOBAL to pass through variable that's outdoors of the function

function filter_where($where = '') {
global $timeframe; // <---- pass it as global
echo ('timeframe2:');echo ($timeframe);
$where .= " AND post_date > '" . date('Y-m-d', strtotime("-$timeframe days")) . "'";
return $where;
}

Or Else You call pass $timeframe like a parameter for your function

function filter_where($where = '', $timeframe ) /* here we pass a variable into function */ {
echo ('timeframe2:');echo ($timeframe);
$where .= " AND post_date > '" . date('Y-m-d', strtotime("-$timeframe days")) . "'";
return $where;
}

call function:

filter_where('', $timeframe);

it isn't that clean as variant with GLOBAL, but nonetheless work though.