From f0b3e72231a6f69928a936c9eeb90e38f4c70551 Mon Sep 17 00:00:00 2001 From: Takumi Date: Fri, 26 Jul 2013 00:16:29 +1000 Subject: [PATCH] Use multiple post metas instead of serialized array --- actions.php | 11 ++++++++--- helpers.php | 52 ++++++++++++++++++++-------------------------------- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/actions.php b/actions.php index 9417bc2f..b3adfb32 100644 --- a/actions.php +++ b/actions.php @@ -23,9 +23,14 @@ function sp_save_post( $post_id ) { if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; if ( !isset( $_POST['sportspress_nonce'] ) || ! wp_verify_nonce( $_POST['sportspress_nonce'], plugin_basename( __FILE__ ) ) ) return $post_id; foreach ( $sportspress as $key => $value ): - if ( is_array( $value ) ) - $value = serialize( $value ); - update_post_meta( $post_id, $key, $value ); + delete_post_meta( $post_id, $key ); + if ( is_array( $value ) ): + foreach ( $value as $single_value ): + add_post_meta( $post_id, $key, $single_value, false ); + endforeach; + else: + update_post_meta( $post_id, $key, $value ); + endif; endforeach; endif; endif; diff --git a/helpers.php b/helpers.php index 9c1fd9dc..cc58b06c 100644 --- a/helpers.php +++ b/helpers.php @@ -110,36 +110,22 @@ if ( ! function_exists( 'sp_team_logo' ) ) { } } -if ( ! function_exists( 'sp_get_teams' ) ) { - function sp_get_teams( $post_id = null ) { - $teams = get_post_meta( $post_id, 'sp_teams', true ); - if ( isset( $teams ) && $teams ) - $teams = (array)unserialize( $teams ); - else - $teams = array(); - return $teams; - } -} - if ( ! function_exists( 'sp_team_checklist' ) ) { function sp_team_checklist( $post_id = null ) { if ( ! isset( $post_id ) ) global $post_id; - $selected = sp_get_teams( $post_id ); + $selected = get_post_meta( $post_id, 'sp_team', false ); $teams = get_pages( array( 'post_type' => 'sp_team') ); foreach ( $teams as $team ): + $parents = get_post_ancestors( $team ); ?>
  • +
  • ', sizeof( $parents ) ); ?> + ', sizeof( $parents ) ); ?>
  • -
    - - -
    -
    -

    - - + - -

    +
    +
    + +
      + +
    +
    +
    +

    + + + + +

    +