Fix table league selector
This commit is contained in:
@@ -115,6 +115,7 @@ function sp_save_post( $post_id ) {
|
|||||||
break;
|
break;
|
||||||
case ( 'sp_table' ):
|
case ( 'sp_table' ):
|
||||||
update_post_meta( $post_id, 'sp_stats', $_POST['sp_stats'] );
|
update_post_meta( $post_id, 'sp_stats', $_POST['sp_stats'] );
|
||||||
|
wp_set_post_terms( $post_id, $_POST['sp_league'], 'sp_league' );
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_team', $_POST['sp_team'] );
|
sp_update_post_meta_recursive( $post_id, 'sp_team', $_POST['sp_team'] );
|
||||||
break;
|
break;
|
||||||
endswitch;
|
endswitch;
|
||||||
|
|||||||
15
helpers.php
15
helpers.php
@@ -94,6 +94,21 @@ if ( !function_exists( 'sp_tax_labels' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !function_exists( 'sp_get_the_term_id' ) ) {
|
||||||
|
function sp_get_the_term_id( $post_id, $taxonomy, $index ) {
|
||||||
|
$terms = get_the_terms( $post_id, $taxonomy );
|
||||||
|
if ( is_array( $terms ) && array_key_exists( $index, $terms ) ):
|
||||||
|
$term = $terms[0];
|
||||||
|
if ( is_object( $term ) && property_exists( $term, 'term_id' ) )
|
||||||
|
return $term->term_id;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
else:
|
||||||
|
return 0;
|
||||||
|
endif;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
|
if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
|
||||||
function sp_dropdown_taxonomies( $args = array() ) {
|
function sp_dropdown_taxonomies( $args = array() ) {
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
|
|||||||
12
table.php
12
table.php
@@ -35,7 +35,7 @@ function sp_table_meta_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sp_table_team_meta( $post ) {
|
function sp_table_team_meta( $post ) {
|
||||||
$league = get_post_meta( $post->ID, 'sp_league', true );
|
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||||
?>
|
?>
|
||||||
<div>
|
<div>
|
||||||
<p class="sp-tab-select">
|
<p class="sp-tab-select">
|
||||||
@@ -44,7 +44,7 @@ function sp_table_team_meta( $post ) {
|
|||||||
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
|
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ),
|
||||||
'taxonomy' => 'sp_league',
|
'taxonomy' => 'sp_league',
|
||||||
'name' => 'sp_league',
|
'name' => 'sp_league',
|
||||||
'selected' => $league
|
'selected' => $league_id
|
||||||
);
|
);
|
||||||
sp_dropdown_taxonomies( $args );
|
sp_dropdown_taxonomies( $args );
|
||||||
?>
|
?>
|
||||||
@@ -61,12 +61,12 @@ function sp_table_team_meta( $post ) {
|
|||||||
function sp_table_stats_meta( $post ) {
|
function sp_table_stats_meta( $post ) {
|
||||||
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
|
||||||
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
||||||
$league = (int)get_post_meta( $post->ID, 'sp_league', true );
|
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||||
$data = sp_array_combine( $teams, sp_array_value( $stats, $league, array() ) );
|
$data = sp_array_combine( $teams, sp_array_value( $stats, $league_id, array() ) );
|
||||||
$placeholders = array();
|
$placeholders = array();
|
||||||
foreach ( $teams as $team ):
|
foreach ( $teams as $team ):
|
||||||
$placeholders[ $team ] = sp_get_stats( $team, 0, $league );
|
$placeholders[ $team ] = sp_get_stats( $team, 0, $league_id );
|
||||||
endforeach;
|
endforeach;
|
||||||
sp_stats_table( $data, $placeholders, $league, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false );
|
sp_stats_table( $data, $placeholders, $league_id, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false );
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user