如何从此输入代码传递$timeframe
变量的值:
<input size="2" id="' . $this->get_field_id('timeframe') . '" name="' . $this->get_field_name('timeframe') . '" type="text" value="' . $timeframe . '" />
以下功能代码:
function filter_where( $where = '' ) {
$where .= " AND post_date > '" . date('Y-m-d', strtotime("-$timeframe days")) ."'";
return $where;}
add_filter( 'posts_where', 'filter_where' );
答案 0 :(得分:1)
根据表单提交的方法,您需要以下其中一种:
$timeframe = $_POST['timeframe'];
或:
$timeframe = $_GET['timeframe'];
要将其传递给该函数,我建议修改函数签名:
function filter_where($where = '', $timeframe) {
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-'.$timeframe.' days')) ."'";
return $where;
}
add_filter( 'posts_where', 'filter_where' );