Save player and staff as delimited single dimensional arrays
This commit is contained in:
@@ -101,8 +101,9 @@ function sp_save_post( $post_id ) {
|
|||||||
foreach ( $sportspress as $key => $value ):
|
foreach ( $sportspress as $key => $value ):
|
||||||
delete_post_meta( $post_id, $key );
|
delete_post_meta( $post_id, $key );
|
||||||
if ( is_array( $value ) ):
|
if ( is_array( $value ) ):
|
||||||
foreach ( $value as $single_value ):
|
$values = new RecursiveIteratorIterator( new RecursiveArrayIterator( $value ) );
|
||||||
add_post_meta( $post_id, $key, $single_value, false );
|
foreach ( $values as $value ):
|
||||||
|
add_post_meta( $post_id, $key, $value, false );
|
||||||
endforeach;
|
endforeach;
|
||||||
else:
|
else:
|
||||||
update_post_meta( $post_id, $key, $value );
|
update_post_meta( $post_id, $key, $value );
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ function sp_event_team_meta( $post ) {
|
|||||||
$limit = get_option( 'sp_event_team_count' );
|
$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);
|
$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);
|
$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++ ):
|
for ( $i = 0; $i < $limit; $i++ ):
|
||||||
?>
|
?>
|
||||||
<div>
|
<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>
|
<li class="wp-tab"><a href="#sp_staff-all"><?php _e( 'Staff', 'sportspress' ); ?></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<?php
|
<?php
|
||||||
sp_post_checklist( $post->ID, 'sp_player', false, 'block', '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' );
|
sp_post_checklist( $post->ID, 'sp_staff', $i == $limit - 1, 'none', 'sp_team', $i );
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
|
|||||||
17
helpers.php
17
helpers.php
@@ -112,16 +112,27 @@ if ( ! function_exists( 'sp_team_logo' ) ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( ! function_exists( 'sp_post_checklist' ) ) {
|
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 ) )
|
if ( ! isset( $post_id ) )
|
||||||
global $post_id;
|
global $post_id;
|
||||||
$obj = get_post_type_object( $meta );
|
$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; ?>;">
|
<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">
|
<ul class="categorychecklist form-no-clear">
|
||||||
<?php
|
<?php
|
||||||
$selected = (array)get_post_meta( $post_id, $meta, false );
|
$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 ) );
|
$posts = get_pages( array( 'post_type' => $meta, 'number' => 0 ) );
|
||||||
if ( empty( $posts ) )
|
if ( empty( $posts ) )
|
||||||
$posts = get_posts( array( 'post_type' => $meta, 'numberposts' => 0 ) );
|
$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 ) ); ?>
|
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
|
||||||
<label class="selectit">
|
<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; ?>
|
<?php echo $post->post_title; ?>
|
||||||
</label>
|
</label>
|
||||||
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>
|
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>
|
||||||
|
|||||||
Reference in New Issue
Block a user