diff --git a/helpers.php b/helpers.php index 6c80a571..9c1fd9dc 100644 --- a/helpers.php +++ b/helpers.php @@ -65,6 +65,32 @@ if ( ! function_exists( 'sp_dropdown_taxonomies' ) ) { } } } +if ( ! function_exists( 'sp_unserialized_posts' ) ) { + function sp_unserialized_posts( $post_id = null, $meta = 'posts', $before = '', $sep = ',', $after = '' ) { + echo $before; + if ( ! isset( $post_id ) ) + global $post_id; + $posts = get_post_meta( $post_id, $meta, true ); + if ( isset( $posts ) && $posts ): + $posts = (array)unserialize( $posts ); + foreach ( $posts as $post ): + $parents = get_post_ancestors( $post ); + $parents = array_combine( array_keys( $parents ), array_reverse( array_values( $parents ) ) ); + foreach ( $parents as $parent ): + if ( !in_array( $parent, $posts ) ) + edit_post_link( get_the_title( $parent ), '', ' ', $parent ); + echo '— '; + endforeach; + edit_post_link( get_the_title( $post ), '', '', $post ); + if ( $post != end( $posts ) ) + echo $sep; + endforeach; + else: + echo '—'; + endif; + echo $after; + } +} if ( ! function_exists( 'sp_team_logo' ) ) { function sp_team_logo( $post_id = null ) { diff --git a/player.php b/player.php index f3d75e0e..eecc3c85 100644 --- a/player.php +++ b/player.php @@ -59,17 +59,7 @@ function sp_player_custom_columns( $column, $post_id ) { echo '—'; break; case 'sp_team': - $teams = sp_get_teams( $post_id ); - foreach ( $teams as $team ): - $parents = get_post_ancestors( $team ); - $parents = array_combine( array_keys( $parents ), array_reverse( array_values( $parents ) ) ); - foreach ( $parents as $parent ): - if ( !in_array( $parent, $teams ) ) - edit_post_link( get_the_title( $parent ), '', ' ', $parent ); - echo '— '; - endforeach; - edit_post_link( get_the_title( $team ), '', '
', $team ); - endforeach; + sp_unserialized_posts( $post_id, 'sp_teams', '', '
' ); break; case 'sp_league': if ( get_the_terms ( $post_id, 'sp_league' ) ) diff --git a/staff.php b/staff.php index da5d8284..06ae8547 100644 --- a/staff.php +++ b/staff.php @@ -38,8 +38,8 @@ function sp_staff_edit_columns( $columns ) { $columns = array( 'cb' => '', 'title' => __( 'Name', 'sportspress' ), - 'sp_team' => __( 'Teams', 'sportspress' ), 'sp_position' => __( 'Positions', 'sportspress' ), + 'sp_team' => __( 'Teams', 'sportspress' ), 'sp_league' => __( 'Leagues', 'sportspress' ), 'sp_season' => __( 'Seasons', 'sportspress' ) ); @@ -57,6 +57,9 @@ function sp_staff_custom_columns( $column ) { else echo '—'; break; + case 'sp_team': + sp_unserialized_posts( $post_id, 'sp_teams', '', '
' ); + break; case 'sp_league': if ( get_the_terms ( $post_id, 'sp_league' ) ) the_terms( $post_id, 'sp_league' );