Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( is_admin() ) {
- add_action( 'wp_ajax_dynamic_dropdown', 'dynamic_dropdown_func' );
- add_action( 'wp_ajax_nopriv_dynamic_dropdown', 'dynamic_dropdown_func' );
- }
- function dynamic_dropdown_func () {
- global $wpdb;
- if (isset($_POST['event'])) {
- $event_id = $_POST['event'];
- $first = get_field('first_day',$event_id);
- $last = get_field('last_day',$event_id);
- $event_dates = '<option value="" disabled selected>Choose Date</option>';
- $event_dates .= '<option value="'.$first.'">'.$first.'</option>';
- while($first<$last) :
- $first = $first + 1;
- $event_dates .= '<option value="'.$first.'">'.$first.'</option>';
- endwhile;
- }
- ob_clean();
- return $event_dates;
- wp_die();
- }
- <?php function date_chooser () {
- $ajax_url = admin_url( 'admin-ajax.php' );
- $grabDates = "
- <script>
- var ajaxUrl = '{$ajax_url}',
- dropdownEvent = jQuery('#chooseEvent'),
- dropdownDate = jQuery('#chooseDate');
- dropdownEvent.on('change', function (e) {
- var value = e.target.selectedOptions[0].value,
- success,
- data;
- if (!!value) {
- data = {
- 'event' : value,
- 'action' : 'dynamic_dropdown'
- };
- success = function ( response ) {
- dropdownDate.html( response );
- };
- jQuery.post( ajaxUrl, data, success );
- }
- });
- </script>";
- return $grabDates;
- }
- echo date_chooser(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement