Calendar post type basic functionality
This commit is contained in:
@@ -63,8 +63,8 @@ if ( !function_exists( 'sportspress_get_post_labels' ) ) {
|
|||||||
'new_item' => sprintf( __( 'New %s', 'sportspress' ), $singular_name ),
|
'new_item' => sprintf( __( 'New %s', 'sportspress' ), $singular_name ),
|
||||||
'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ),
|
'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ),
|
||||||
'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
|
'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
|
||||||
'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ),
|
'not_found' => sprintf( __( 'No %s found.', 'sportspress' ), $lowercase_name ),
|
||||||
'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $lowercase_name ),
|
'not_found_in_trash' => sprintf( __( 'No %s found in trash.', 'sportspress' ), $lowercase_name ),
|
||||||
'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':'
|
'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':'
|
||||||
);
|
);
|
||||||
return $labels;
|
return $labels;
|
||||||
@@ -86,7 +86,7 @@ if ( !function_exists( 'sportspress_get_term_labels' ) ) {
|
|||||||
'parent_item' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ),
|
'parent_item' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ),
|
||||||
'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':',
|
'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':',
|
||||||
'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
|
'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ),
|
||||||
'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name )
|
'not_found' => sprintf( __( 'No %s found.', 'sportspress' ), $lowercase_name )
|
||||||
);
|
);
|
||||||
return $labels;
|
return $labels;
|
||||||
}
|
}
|
||||||
@@ -493,6 +493,49 @@ if ( !function_exists( 'sportspress_get_var_equations' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !function_exists( 'sportspress_edit_calendar_table' ) ) {
|
||||||
|
function sportspress_edit_calendar_table( $data = array() ) {
|
||||||
|
if ( empty( $data ) ):
|
||||||
|
printf( __( 'No %s found.', 'sportspress' ), __( 'events', 'sportspress' ) );
|
||||||
|
return false;
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
<div class="sp-data-table-container">
|
||||||
|
<table class="widefat sp-data-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th><?php _e( 'Event', 'sportspress' ); ?></th>
|
||||||
|
<th><?php _e( 'Date', 'sportspress' ); ?></th>
|
||||||
|
<th><?php _e( 'Time', 'sportspress' ); ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
$i = 0;
|
||||||
|
foreach ( $data as $event ):
|
||||||
|
?>
|
||||||
|
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||||
|
<td>
|
||||||
|
<?php echo $event->post_title; ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo mysql2date( get_option('date_format'), $event->post_date ); ?>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php echo mysql2date( get_option('time_format'), $event->post_date ); ?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
$i++;
|
||||||
|
endforeach;
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sportspress_edit_league_table' ) ) {
|
if ( !function_exists( 'sportspress_edit_league_table' ) ) {
|
||||||
function sportspress_edit_league_table( $columns = array(), $data = array(), $placeholders = array() ) {
|
function sportspress_edit_league_table( $columns = array(), $data = array(), $placeholders = array() ) {
|
||||||
?>
|
?>
|
||||||
@@ -986,6 +1029,50 @@ if ( !function_exists( 'sportspress_solve' ) ) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !function_exists( 'sportspress_get_calendar_data' ) ) {
|
||||||
|
function sportspress_get_calendar_data( $post_id ) {
|
||||||
|
$seasons = get_the_terms( $post_id, 'sp_season' );
|
||||||
|
$venues = get_the_terms( $post_id, 'sp_venue' );
|
||||||
|
|
||||||
|
if ( ! $seasons || ! $venues )
|
||||||
|
return array();
|
||||||
|
|
||||||
|
$season_ids = array();
|
||||||
|
foreach( $seasons as $season ):
|
||||||
|
$season_ids[] = $season->term_id;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$venue_ids = array();
|
||||||
|
foreach( $venues as $venue ):
|
||||||
|
$venue_ids[] = $venue->term_id;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'sp_event',
|
||||||
|
'numberposts' => -1,
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'orderby' => 'post_date',
|
||||||
|
'order' => 'ASC',
|
||||||
|
'tax_query' => array(
|
||||||
|
array(
|
||||||
|
'taxonomy' => 'sp_season',
|
||||||
|
'field' => 'id',
|
||||||
|
'terms' => $season_ids
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'taxonomy' => 'sp_venue',
|
||||||
|
'field' => 'id',
|
||||||
|
'terms' => $venue_ids
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
$events = get_posts( $args );
|
||||||
|
|
||||||
|
return $events;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
||||||
function sportspress_get_league_table_data( $post_id, $breakdown = false ) {
|
function sportspress_get_league_table_data( $post_id, $breakdown = false ) {
|
||||||
$div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 );
|
$div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 );
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ function sportspress_calendar_post_init() {
|
|||||||
'labels' => $labels,
|
'labels' => $labels,
|
||||||
'public' => true,
|
'public' => true,
|
||||||
'hierarchical' => false,
|
'hierarchical' => false,
|
||||||
'supports' => array( 'title', 'author', 'excerpt' ),
|
'supports' => array( 'title', 'author', 'thumbnail', 'excerpt' ),
|
||||||
'register_meta_box_cb' => 'sportspress_calendar_meta_init',
|
'register_meta_box_cb' => 'sportspress_calendar_meta_init',
|
||||||
'rewrite' => array( 'slug' => get_option( 'sp_calendar_slug', 'calendars' ) ),
|
'rewrite' => array( 'slug' => get_option( 'sp_calendar_slug', 'calendars' ) ),
|
||||||
'show_in_menu' => 'edit.php?post_type=sp_event',
|
'show_in_menu' => 'edit.php?post_type=sp_event',
|
||||||
@@ -32,44 +32,18 @@ function sportspress_calendar_edit_columns() {
|
|||||||
add_filter( 'manage_edit-sp_calendar_columns', 'sportspress_calendar_edit_columns' );
|
add_filter( 'manage_edit-sp_calendar_columns', 'sportspress_calendar_edit_columns' );
|
||||||
|
|
||||||
function sportspress_calendar_meta_init( $post ) {
|
function sportspress_calendar_meta_init( $post ) {
|
||||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
$seasons = get_the_terms( $post->ID, 'sp_season' );
|
||||||
|
$venues = get_the_terms( $post->ID, 'sp_venue' );
|
||||||
|
|
||||||
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_calendar_team_meta', 'sp_calendar', 'side', 'high' );
|
add_meta_box( 'sp_eventsdiv', __( 'Events', 'sportspress' ), 'sportspress_calendar_events_meta', 'sp_calendar', 'normal', 'high' );
|
||||||
|
|
||||||
if ( $teams && $teams != array(0) ):
|
|
||||||
add_meta_box( 'sp_columnsdiv', __( 'League Table', 'sportspress' ), 'sportspress_calendar_columns_meta', 'sp_calendar', 'normal', 'high' );
|
|
||||||
endif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sportspress_calendar_team_meta( $post, $test ) {
|
function sportspress_calendar_events_meta( $post ) {
|
||||||
$league_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 );
|
$seasons = get_the_terms( $post->ID, 'sp_season' );
|
||||||
?>
|
|
||||||
<div>
|
|
||||||
<p class="sp-tab-select">
|
|
||||||
<?php
|
|
||||||
$args = array(
|
|
||||||
'taxonomy' => 'sp_season',
|
|
||||||
'name' => 'sp_season',
|
|
||||||
'selected' => $league_id,
|
|
||||||
'value' => 'term_id'
|
|
||||||
);
|
|
||||||
sportspress_dropdown_taxonomies( $args );
|
|
||||||
?>
|
|
||||||
</p>
|
|
||||||
<?php
|
|
||||||
sportspress_post_checklist( $post->ID, 'sp_team', 'block', 'sp_season' );
|
|
||||||
sportspress_post_adder( 'sp_team' );
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
sportspress_nonce();
|
|
||||||
}
|
|
||||||
|
|
||||||
function sportspress_calendar_columns_meta( $post ) {
|
$data = sportspress_get_calendar_data( $post->ID, true );
|
||||||
|
|
||||||
// list( $columns, $data, $placeholders, $merged ) = sportspress_get_league_calendar_data( $post->ID, true );
|
sportspress_edit_calendar_table( $data );
|
||||||
|
|
||||||
// sportspress_edit_league_calendar( $columns, $data, $placeholders );
|
|
||||||
|
|
||||||
sportspress_nonce();
|
sportspress_nonce();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user