Save player and staff as delimited single dimensional arrays

This commit is contained in:
Takumi
2013-07-27 21:23:27 +10:00
parent 7c9d55cd93
commit 18eee98728
3 changed files with 20 additions and 7 deletions

View File

@@ -101,8 +101,9 @@ function sp_save_post( $post_id ) {
foreach ( $sportspress as $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 );
$values = new RecursiveIteratorIterator( new RecursiveArrayIterator( $value ) );
foreach ( $values as $value ):
add_post_meta( $post_id, $key, $value, false );
endforeach;
else:
update_post_meta( $post_id, $key, $value );

View File

@@ -36,6 +36,7 @@ function sp_event_team_meta( $post ) {
$limit = get_option( 'sp_event_team_count' );
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0);
$scores = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_score', false ), 0, $limit ), $limit, 0);
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
for ( $i = 0; $i < $limit; $i++ ):
?>
<div>
@@ -58,8 +59,8 @@ function sp_event_team_meta( $post ) {
<li class="wp-tab"><a href="#sp_staff-all"><?php _e( 'Staff', 'sportspress' ); ?></a></li>
</ul>
<?php
sp_post_checklist( $post->ID, 'sp_player', false, 'block', 'sp_team' );
sp_post_checklist( $post->ID, 'sp_staff', $i == $limit - 1, 'none', 'sp_team' );
sp_post_checklist( $post->ID, 'sp_player', false, 'block', 'sp_team', $i );
sp_post_checklist( $post->ID, 'sp_staff', $i == $limit - 1, 'none', 'sp_team', $i );
?>
</div>
<?php

View File

@@ -112,16 +112,27 @@ if ( ! function_exists( 'sp_team_logo' ) ) {
}
if ( ! function_exists( 'sp_post_checklist' ) ) {
function sp_post_checklist( $post_id = null, $meta = 'post', $add_new_item = true, $display = 'block', $data = null ) {
function sp_post_checklist( $post_id = null, $meta = 'post', $add_new_item = true, $display = 'block', $data = null, $index = null ) {
if ( ! isset( $post_id ) )
global $post_id;
$obj = get_post_type_object( $meta );
?>
<div id="<?php echo $meta; ?>-all" class="posttypediv wp-tab-panel sp-tab-panel" style="display: <?php echo $display; ?>;">
<input type="hidden" value="0" name="sportspress[<?php echo $meta; ?>]" />
<input type="hidden" value="0" name="sportspress[<?php echo $meta; ?>]<?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]" />
<ul class="categorychecklist form-no-clear">
<?php
$selected = (array)get_post_meta( $post_id, $meta, false );
if ( isset( $index ) ):
$keys = array_keys( $selected, 0 );
if ( array_key_exists( $index, $keys ) ):
$offset = $keys[ $index ];
$end = sizeof( $selected );
if ( array_key_exists( $index + 1, $keys ) )
$end = $keys[ $index + 1 ];
$length = $end - $offset;
$selected = array_slice( $selected, $offset, $length );
endif;
endif;
$posts = get_pages( array( 'post_type' => $meta, 'number' => 0 ) );
if ( empty( $posts ) )
$posts = get_posts( array( 'post_type' => $meta, 'numberposts' => 0 ) );
@@ -140,7 +151,7 @@ if ( ! function_exists( 'sp_post_checklist' ) ) {
?>">
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
<label class="selectit">
<input type="checkbox" value="<?php echo $post->ID; ?>" name="sportspress[<?php echo $meta; ?>][]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
<input type="checkbox" value="<?php echo $post->ID; ?>" name="sportspress[<?php echo $meta; ?>]<?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
<?php echo $post->post_title; ?>
</label>
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>