Last active
August 29, 2015 13:57
-
-
Save joshmoto/9465715 to your computer and use it in GitHub Desktop.
fastest way to get array block based on value contained within the block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// results generator | |
function node_modify_riders_array($rider_id) | |
{ | |
$fields = get_field("rider_series_data", $rider_id); | |
foreach($fields as $field_key => $field_val) | |
{ | |
$new_fields[$field_val["series"]] = $field_val; | |
} | |
return $new_fields; | |
} | |
function results_table_generator( $post_id, $event_id ) { | |
$series = wp_get_post_terms($event_id, 'series'); | |
$results_tables = get_field('results_table', $event_id); | |
if($results_tables) | |
{ | |
foreach($results_tables as $results_table) | |
{ | |
$type = $results_table['type']; | |
$data = $results_table['data']; | |
echo '<div class="table-responsive">'; | |
echo '<table class="table table-condensed table-striped table-data" style="width:100%">'; | |
echo '<tbody>'; | |
if($data) | |
{ | |
foreach($data as $row) | |
{ | |
$rider_id = $row['rider']; | |
if (!empty($rider_id)) { | |
$rider_series_data = node_modify_riders_array($rider_id); | |
$series_id = $series[0]->term_id; | |
$name = get_the_title( $rider_id ); | |
$nationality = get_field('rider_nationality', $rider_id); | |
$time = $row['time']; | |
$team = $rider_series_data[$series_id]["team"]; | |
$contstructor = $rider_series_data[$series_id]["constructor"]; | |
$machine = $rider_series_data[$series_id]["machine"]; | |
$race_number = $rider_series_data[$series_id]["race_number"]; | |
echo '<tr>'; | |
echo '<td class="table-label">'.$name.' | '.$rider_id.'</td>'; | |
echo '<td class="table-label">'.$race_number.'</td>'; // not returning anything | |
echo '<td class="table-label">'.$nationality.'</td>'; | |
echo '<td class="table-label">'.$team)'</td>'; // not returning anything | |
echo '<td class="table-label">'.$contstructor.'</td>'; // not returning anything | |
echo '<td class="table-label">'.$machine.'</td>'; // not returning anything | |
echo '<td class="table-value">'.$time.'</td>'; | |
echo '<td class="table-value">'.$series_id.'</td>'; | |
echo '</tr>'; | |
} | |
} | |
} | |
echo '</tbody>'; | |
echo '</table>'; | |
echo '</div>'; | |
echo '<hr/>'; | |
} | |
echo '</ul>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment