开发者

How to Get the value of variable inside function in PHP:

How to pass the value of $timeframe variable from this input code:

<input size="2" id="' . $this->get_field_id('timeframe') . '" name="' . $this->get_field_name('timeframe') . '" type="text" value="' . $timeframe . '" /> 

To this function code below:

function filter_whe开发者_如何学Pythonre( $where = '' ) {
$where .= " AND post_date > '" . date('Y-m-d', strtotime("-$timeframe days")) ."'";
return $where;}
add_filter( 'posts_where', 'filter_where' );


Depending on the method of the form submission, you want one of these:

$timeframe = $_POST['timeframe'];

or:

$timeframe = $_GET['timeframe'];

To pass it to that function I would suggest modifying the function signature:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜