Let’s say you have a form that sends the data in the following way:
<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>
Now you want to query some posts based on users choice right? This is where $_POST
comes in handy:
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;
}
}
You have to extend this code to fit your needs, such as defining what to do if there is no form data.