From bf0aab149b0198a05b4dfa0d42e5d54ae8bb8420 Mon Sep 17 00:00:00 2001 From: Takumi Date: Fri, 2 Aug 2013 00:07:25 +1000 Subject: [PATCH] Fix table league selector --- actions.php | 1 + helpers.php | 15 +++++++++++++++ table.php | 12 ++++++------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/actions.php b/actions.php index 538f510c..72897e5d 100644 --- a/actions.php +++ b/actions.php @@ -115,6 +115,7 @@ function sp_save_post( $post_id ) { break; case ( 'sp_table' ): 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'] ); break; endswitch; diff --git a/helpers.php b/helpers.php index f9ab26c4..1877f4f7 100644 --- a/helpers.php +++ b/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' ) ) { function sp_dropdown_taxonomies( $args = array() ) { $defaults = array( diff --git a/table.php b/table.php index 985d1cba..628481b3 100644 --- a/table.php +++ b/table.php @@ -35,7 +35,7 @@ function sp_table_meta_init() { } 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 ); ?>

@@ -44,7 +44,7 @@ function sp_table_team_meta( $post ) { 'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Leagues', 'sportspress' ) ), 'taxonomy' => 'sp_league', 'name' => 'sp_league', - 'selected' => $league + 'selected' => $league_id ); sp_dropdown_taxonomies( $args ); ?> @@ -61,12 +61,12 @@ function sp_table_team_meta( $post ) { function sp_table_stats_meta( $post ) { $teams = (array)get_post_meta( $post->ID, 'sp_team', false ); $stats = (array)get_post_meta( $post->ID, 'sp_stats', true ); - $league = (int)get_post_meta( $post->ID, 'sp_league', true ); - $data = sp_array_combine( $teams, sp_array_value( $stats, $league, array() ) ); + $league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 ); + $data = sp_array_combine( $teams, sp_array_value( $stats, $league_id, array() ) ); $placeholders = array(); foreach ( $teams as $team ): - $placeholders[ $team ] = sp_get_stats( $team, 0, $league ); + $placeholders[ $team ] = sp_get_stats( $team, 0, $league_id ); 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 ); } ?> \ No newline at end of file