sorry can I know where is this? do you want to set min/max date in the date picker ?
Yes, thank you for the response. I mean the datepicker for the event search fields on the front end, not the admin.
So on my Events page I have the advanced search form available for visitors to select a date range of events.
I’m trying to grey-out the dates before and after available event dates.
I suppose for the minDate I’d like it to not allow dates further than 1 month in the past. I dont necessarily need to ‘pick up the first start_date’ as I mentioned above.
But for the maxDate I’d like to automatically detect the end_date furthest in the future that is available within my events and use that date as my maxDate (max selectable date) for the datepicker.
I see, however you might need additional php coding to do this with some jquery to make this work; eg. you can use something like this to get the event dates then do you jquery coding
$EM_Events = EM_Events::get(array('orderby'=>'start_date'));
foreach ( $EM_Events as $EM_Event ) {
echo $EM_Event->event_id;
}
Thanks, angelo. Your reply is much appreciated.
I found something that works.
I first tried
$mydates = EM_Events::get(array('orderby'=>'event_end_date', 'order' => 'DESC', 'limit' => 1));
And was able to echo the last end date by putting it into a foreach like this
foreach ( $mydates as $mydate ) {echo $mydate;}
But it displayed the result as yy-mm-dd.
In order to put the date into the jquery that the datepicker would read, i needed mm/dd/yy .
So I tried this and it seems to work. Do you think doing it this way, with an explode, is a good way to do it? Do you know a way to do it from the EM_Events::get array above?
global $wpdb;
$mydates = $wpdb->get_col("SELECT MAX(event_end_date) FROM wp_em_events LIMIT 1");
foreach ( $mydates as $mydate ) {
$mydatex = explode("-", $mydate);
$mydayex = $mydatex[1];
$myyearex = $mydatex[0];
$mymonthex = $mydatex[2];
$myenddate = $mydayex.'/'.$mymonthex.'/'.$myyearex.'/';
}
Then, in the jquery I defined ‘$myenddate’ as the variable ‘end’
<script>
function em_setup_datepicker(wrap){
wrap = jQuery(wrap);
//default picker vals
if(wrap.find('.em-date-range-search')){
var end = new Date("<?php echo $myenddate; ?>");
var datepicker_vals = { altFormat: "yy-mm-dd", changeMonth: true, changeYear: true, firstDay : EM.firstDay, yearRange:'-100:+10', minDate: '-1mm', maxDate: end };}
else{...
This is all within my theme in Plugins > events-manager > templates > search > scope.php