Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. if ( is_admin() ) {
  2. add_action( 'wp_ajax_dynamic_dropdown', 'dynamic_dropdown_func' );
  3. add_action( 'wp_ajax_nopriv_dynamic_dropdown', 'dynamic_dropdown_func' );
  4. }
  5. function dynamic_dropdown_func () {
  6. global $wpdb;
  7. if (isset($_POST['event'])) {
  8. $event_id = $_POST['event'];
  9. $first = get_field('first_day',$event_id);
  10. $last = get_field('last_day',$event_id);
  11. $event_dates = '<option value="" disabled selected>Choose Date</option>';
  12. $event_dates .= '<option value="'.$first.'">'.$first.'</option>';
  13. while($first<$last) :
  14. $first = $first + 1;
  15. $event_dates .= '<option value="'.$first.'">'.$first.'</option>';
  16. endwhile;
  17. }
  18. ob_clean();
  19. return $event_dates;
  20. wp_die();
  21. }
  22.  
  23. <?php function date_chooser () {
  24. $ajax_url = admin_url( 'admin-ajax.php' );
  25. $grabDates = "
  26. <script>
  27. var ajaxUrl = '{$ajax_url}',
  28. dropdownEvent = jQuery('#chooseEvent'),
  29. dropdownDate = jQuery('#chooseDate');
  30. dropdownEvent.on('change', function (e) {
  31. var value = e.target.selectedOptions[0].value,
  32. success,
  33. data;
  34. if (!!value) {
  35. data = {
  36. 'event' : value,
  37. 'action' : 'dynamic_dropdown'
  38. };
  39. success = function ( response ) {
  40. dropdownDate.html( response );
  41. };
  42. jQuery.post( ajaxUrl, data, success );
  43. }
  44. });
  45. </script>";
  46. return $grabDates;
  47. }
  48. echo date_chooser(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement