假设您有一个表单,它以以下方式发送数据:
<form method="post" name="car-select" action="<?php echo site_url(\'/my-page/\'); ?>">
<select name="make">
<option value="benz">Benz</option>
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
</select>
<input type="submit" value="Find my dream car!"/>
</form>
现在你想根据用户的选择查询一些帖子,对吗?这就是
$_POST
方便快捷:
add_shortcode(\'my-shortcode\',\'my_shortcode_function\');
function my_shortcode_function($atts){
// Get the ID from shortcode
$id = $atts[\'post_id\'];
// Check if the form data has been sent
if (isset($_POST[\'make\']) && $id){
$car_manufacturer = $_POST[\'make\'];
//Now, you have the form\'s data. Do whatever you want with it
return $my_shortcode_values;
}
}
您必须扩展此代码以满足您的需要,例如定义没有表单数据时要做什么。