Add yesterday, tomorrow, last week, and next week options to calendar date selector

This commit is contained in:
Brian Miyaji
2017-11-09 00:10:19 +11:00
parent 3817fcbf33
commit 563135264d
3 changed files with 52 additions and 15 deletions

View File

@@ -134,22 +134,54 @@ class SP_Calendar extends SP_Secondary_Post {
);
if ( $this->date !== 0 ):
if ( $this->date == 'w' ):
$args['year'] = date_i18n('Y');
$args['w'] = date_i18n('W');
elseif ( $this->date == 'day' ):
$args['year'] = date_i18n('Y');
$args['day'] = date_i18n('j');
$args['monthnum'] = date_i18n('n');
elseif ( $this->date == 'range' ):
if ( $this->relative ):
add_filter( 'posts_where', array( $this, 'relative' ) );
else:
add_filter( 'posts_where', array( $this, 'range' ) );
endif;
endif;
switch ( $this->date ):
case '-day':
$date = new DateTime( date_i18n('Y-m-d') );
$date->modify( '-1 day' );
$args['year'] = $date->format('Y');
$args['day'] = $date->format('j');
$args['monthnum'] = $date->format('n');
break;
case 'day':
$args['year'] = date_i18n('Y');
$args['day'] = date_i18n('j');
$args['monthnum'] = date_i18n('n');
break;
case '+day':
$date = new DateTime( date_i18n('Y-m-d') );
$date->modify( '+1 day' );
$args['year'] = $date->format('Y');
$args['day'] = $date->format('j');
$args['monthnum'] = $date->format('n');
break;
case '-w':
$date = new DateTime( date_i18n('Y-m-d') );
$date->modify( '-1 week' );
$args['year'] = $date->format('Y');
$args['w'] = $date->format('W');
break;
case 'w':
$args['year'] = date_i18n('Y');
$args['w'] = date_i18n('W');
break;
case '+w':
$date = new DateTime( date_i18n('Y-m-d') );
$date->modify( '+1 week' );
$args['year'] = $date->format('Y');
$args['w'] = $date->format('W');
break;
case 'range':
if ( $this->relative ):
add_filter( 'posts_where', array( $this, 'relative' ) );
else:
add_filter( 'posts_where', array( $this, 'range' ) );
endif;
break;
endswitch;
endif;
pr( $args );
if ( $this->league ):
$league_ids = array( $this->league );
endif;