更新时间:2023-02-12 08:25:06
I feel that in this case, because what you need is dynamic, you could look into using Wordpress's built in Ajax to handle this one. So, what you could do is to trigger an ajax call on change for that select field to do something like this
jQuery('act_select_field').change(function(){
jQuery.ajax({
url: "/wp-admin/admin-ajax.php",
type: 'POST',
data: {
action: 'get_related_act_times',
act_id: //send through the act ID value,
},
dataType: 'html',
success: function (result) {
//Use the html to populate your time select field
},
error: function (errorThrown) {
console.log(errorThrown);
}
});
})
Then, in your functions.php, register a function to handle this call, like this:
add_action('wp_ajax_get_related_act_times', 'get_act_times');
add_action('wp_ajax_nopriv_get_related_act_times', 'get_act_times');
/**
* Get a list of events from Clear Bookings
*/
function get_act_times(){
$act_id = $_POST['act_id'];
$related_times = get_field('times_repeater_field',$act_id);
foreach($realted_times as $time){
//Build up your select html here
}
echo select_html
die();
}
If you want to read a bit more about the Admin Ajax side of things, the Codex has a lot of information: https://codex.wordpress.org/AJAX_in_Plugins. This should hopefully get you started on dynamically populating your second dropdown - although you'll need to tweak the code to work on your own system