Hi,
I’m developping a website for a customer and I have some trouble.
They have many travel put in the event organiser. Some travel have same day in common.
When I clic on a date in the widget calendar, who is the start day of the travel, the archive-event display all current travel at the day.
Example :
travelA : from 2 april to 15 april
travelB : from 10 april to 20april
in the widget calendar, i have a link on the 2 april and other on the 10 april.
If i clic on the 10 april, the event archive display first the travelA and after the travelB. I want only travel B. or eventually, travelB before (start this day) and after current travel.
Can you help me ?
riesseg
Clicking on a date on the widget calendar should list all events that are ‘running’ that day – so events that started before that day, but have not finished yet will be displayed. So in your example, clicking on the 10th should display both events.
The following should change the default behaviour (but its untested):
add_action( 'pre_get_posts', 'my_alter_date_event_archives', 11 );
function my_alter_date_event_archives( $query ){
//If querying for all events on a given date (month, or year), set the date parameters
if( !empty( $query->query_vars['ondate' ] ) && $query->is_main_query() ) {
$ondate_start = str_replace('/','-',$query->query_vars['ondate']);
$ondate_end = str_replace('/','-',$query->query_vars['ondate']);
//Expect 2013 (year - $parts =1 ), 2013-02 (month - $parts =2 ) or 2013-02-28 (date - $parts =3).
$parts = count(explode('-',$ondate_start));
if( $parts == 1 && is_numeric($ondate_start) ){
//Numeric - interpret as year
$ondate_start .= '-01-01';
$ondate_end .= '-12-31';
}elseif( $parts == 2 ){
// 2013-02 format: interpret as month
$ondate_start .= '-01';
try{
$end = new DateTime($ondate_start);
$ondate_end = $end->format('Y-m-t');
}catch( Exception $e){
$query->set('ondate',false);
break;
}
}
$query->set('post_type', 'event');
//Get events that start on specified date/month/year
$query->set('event_start_after', $ondate_start);
$query->set('event_start_before', $ondate_end);
}//Endif querying by date/month/year
}
Stephen Harris
Awesome.
It’s work perfectly. I add this piece of code in function.php, and tatsa, just magic.
Thank you for your reactivity and your help.
Thanks !
riesseg