Filter events based on format (Competitive, Friendly, Tournament etc)

This commit is contained in:
savvasha
2018-08-28 10:39:24 +03:00
parent fea34c7ff2
commit c4a51e2a9b
5 changed files with 56 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ class SP_Meta_Box_Calendar_Details {
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_future = get_post_meta( $post->ID, 'sp_date_future', true );
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
$event_format = get_post_meta( $post->ID, 'sp_event_format', true );
$day = get_post_meta( $post->ID, 'sp_day', true );
$teams = get_post_meta( $post->ID, 'sp_team', false );
$table_id = get_post_meta( $post->ID, 'sp_table', true );
@@ -49,6 +50,15 @@ class SP_Meta_Box_Calendar_Details {
sp_dropdown_statuses( $args );
?>
</p>
<p><strong><?php _e( 'Event Format', 'sportspress' ); ?></strong></p>
<p>
<select name="sp_event_format" class="postform">
<option value="all">All</option>
<?php foreach ( SP()->formats->event as $key => $format ): ?>
<option value="<?php echo $key; ?>" <?php selected( $event_format, $key ); ?>><?php echo $format; ?></option>
<?php endforeach; ?>
</select>
</p>
<div class="sp-date-selector">
<p><strong><?php _e( 'Date', 'sportspress' ); ?></strong></p>
<p>
@@ -139,6 +149,7 @@ class SP_Meta_Box_Calendar_Details {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_caption', esc_attr( sp_array_value( $_POST, 'sp_caption', 0 ) ) );
update_post_meta( $post_id, 'sp_status', sp_array_value( $_POST, 'sp_status', 0 ) );
update_post_meta( $post_id, 'sp_event_format', sp_array_value( $_POST, 'sp_event_format', 0 ) );
update_post_meta( $post_id, 'sp_date', sp_array_value( $_POST, 'sp_date', 0 ) );
update_post_meta( $post_id, 'sp_date_from', sp_array_value( $_POST, 'sp_date_from', null ) );
update_post_meta( $post_id, 'sp_date_to', sp_array_value( $_POST, 'sp_date_to', null ) );

View File

@@ -423,6 +423,18 @@ class SP_AJAX {
?>
</label>
</p>
<p>
<label>
<?php _e( 'Format:', 'sportspress' ); ?>
<select name="format" class="postform">
<option value="default">Default</option>
<option value="all">All</option>
<?php foreach ( SP()->formats->event as $key => $format ): ?>
<option value="<?php echo $key; ?>"><?php echo $format; ?></option>
<?php endforeach; ?>
</select>
</label>
</p>
<div class="sp-date-selector">
<p><?php _e( 'Date:', 'sportspress' ); ?>
<?php
@@ -617,6 +629,18 @@ class SP_AJAX {
?>
</label>
</p>
<p>
<label>
<?php _e( 'Format:', 'sportspress' ); ?>
<select name="format" class="postform">
<option value="default">Default</option>
<option value="all">All</option>
<?php foreach ( SP()->formats->event as $key => $format ): ?>
<option value="<?php echo $key; ?>"><?php echo $format; ?></option>
<?php endforeach; ?>
</select>
</label>
</p>
<div class="sp-date-selector">
<p><?php _e( 'Date:', 'sportspress' ); ?>
<?php
@@ -1121,6 +1145,7 @@ class SP_AJAX {
args.season = $div.find('[name=season]').val();
args.venue = $div.find('[name=venue]').val();
args.status = $div.find('[name=status]').val();
args.format = $div.find('[name=format]').val();
args.date = $div.find('[name=date]').val();
args.date_from = $div.find('[name=date_from]').val();
args.date_to = $div.find('[name=date_to]').val();
@@ -1140,6 +1165,7 @@ class SP_AJAX {
args.season = $div.find('[name=season]').val();
args.venue = $div.find('[name=venue]').val();
args.status = $div.find('[name=status]').val();
args.format = $div.find('[name=format]').val();
args.date = $div.find('[name=date]').val();
args.date_from = $div.find('[name=date_from]').val();
args.date_to = $div.find('[name=date_to]').val();

View File

@@ -48,6 +48,9 @@ class SP_Calendar extends SP_Secondary_Post {
/** @var int The event ID. */
public $event;
/** @var integer The event format slug. */
public $event_format;
/**
* __construct function.
@@ -102,6 +105,9 @@ class SP_Calendar extends SP_Secondary_Post {
if ( ! $this->day )
$this->day = get_post_meta( $this->ID, 'sp_day', true );
if ( ! $this->event_format )
$this->event_format = get_post_meta( $this->ID, 'sp_event_format', true );
if ( ! $this->number )
$this->number = -1;
@@ -205,6 +211,13 @@ class SP_Calendar extends SP_Secondary_Post {
);
endif;
if ( $this->event_format && 'all' != $this->event_format ):
$args['meta_query'][] = array(
'key' => 'sp_format',
'value' => $this->event_format,
);
endif;
if ( $this->day ):
$args['meta_query'][] = array(
'key' => 'sp_day',

View File

@@ -14,6 +14,7 @@ $defaults = array(
'event' => null,
'title' => false,
'status' => 'default',
'format' => 'all',
'date' => 'default',
'date_from' => 'default',
'date_to' => 'default',
@@ -48,6 +49,8 @@ extract( $defaults, EXTR_SKIP );
$calendar = new SP_Calendar( $id );
if ( $status != 'default' )
$calendar->status = $status;
if ( $format != 'all' )
$calendar->event_format = $format;
if ( $date != 'default' )
$calendar->date = $date;
if ( $date_from != 'default' )

View File

@@ -13,6 +13,7 @@ $defaults = array(
'id' => null,
'title' => false,
'status' => 'default',
'format' => 'all',
'date' => 'default',
'date_from' => 'default',
'date_to' => 'default',
@@ -48,6 +49,8 @@ extract( $defaults, EXTR_SKIP );
$calendar = new SP_Calendar( $id );
if ( $status != 'default' )
$calendar->status = $status;
if ( $format != 'all' )
$calendar->event_format = $format;
if ( $date != 'default' )
$calendar->date = $date;
if ( $date_from != 'default' )