Last active
May 17, 2018 16:19
-
-
Save asha23/26e2528e6dab982c2943ab29c43f635a to your computer and use it in GitHub Desktop.
Method for merging 2 ACF repeater fields then using one loop to output them
This file contains hidden or 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
| foreach ($terms as $term) : | |
| $speciality = $term->term_id; | |
| $speciality_val = $speciality; | |
| $args_hs = array( | |
| 'numberposts' => -1, | |
| 'post_type' => 'clinician', | |
| 'suppress_filters' => false, | |
| 'meta_key' => 'hospitals_and_specialities_UNIQUE8765678_speciality', | |
| 'meta_value' => $speciality, | |
| ); | |
| // query | |
| $the_query_hs = new WP_Query($args_hs); | |
| $docs = $the_query_hs->posts; | |
| //var_dump($docs); | |
| uasort($docs, 'mainSort'); | |
| if ($docs): // Only show listing if it has content | |
| ?> | |
| <tr class="heading-row"> | |
| <td colspan="6"> | |
| <h5 style=""><?php echo $term->name; ?></h5> | |
| </td> | |
| </tr> | |
| <?php | |
| endif; | |
| $rep_merge = array(); | |
| foreach ($docs as $doc): | |
| $repeater = get_field('waiting-times-for-clinics', $doc->ID); | |
| $repeater_hs = get_field('hospitals_and_specialities', $doc->ID); | |
| $title = get_the_title($doc->ID); | |
| $link = get_permalink($doc->ID); | |
| $thumbnail = get_the_post_thumbnail_url($doc->ID, 'mini-thumbnail'); | |
| // Merge the two repeaters | |
| array_push($rep_merge, $repeater); | |
| array_push($rep_merge, $repeater_hs); | |
| foreach ($rep_merge[0] as $index => $row) : | |
| $now_booking = $row['now_booking']; | |
| $bookDate = DateTime::createFromFormat('Ymd', $now_booking); | |
| $waiting = $today->diff($bookDate); | |
| $interval = $waiting->format('%a') / 7; | |
| $weeks = number_format($interval, 1) + 0; | |
| $speciality_id = $rep_merge[1][$index]['speciality']; | |
| $hospital_id = $rep_merge[1][$index]['hospital']; | |
| $speciality = get_term_by('term_taxonomy_id', $speciality_id, 'taxonomies'); | |
| $hospital = get_term_by('term_taxonomy_id', $hospital_id, 'taxonomies'); | |
| $speciality_output = $speciality->name; | |
| $hospital_output = $hospital->name; | |
| if ($speciality->term_id == $speciality_val): | |
| ?> | |
| <tr class="link-element" data-link="<?php echo $link; ?>"> | |
| <td> | |
| <img src="<?php echo $thumbnail; ?>" alt="<?php echo $title; ?>"> | |
| </td> | |
| <td data-column="CONSULTANT"> | |
| <a href="<?php echo $link; ?>"><?php echo $title; ?></a> | |
| </td> | |
| <td data-column="SPECIALITY"> | |
| <?php if ($speciality): echo $speciality_output; endif; ?> | |
| </td> | |
| <td data-column="CLINICS AT"> | |
| <?php if ($hospital): echo $hospital_output; endif; ?> | |
| </td> | |
| <td data-column="N.WEEKS WAITING"> | |
| <?php if ($weeks > 0 || $weeks = !null): echo $weeks; endif; ?> | |
| </td> | |
| <td data-column="NOW BOOKING"> | |
| <?php if ($now_booking): echo date('d/m/Y', strtotime($now_booking)); endif; ?> | |
| </td> | |
| </tr> | |
| <?php | |
| endif; | |
| endforeach; | |
| $rep_merge = array(); // Empty the array | |
| endforeach; | |
| endforeach; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment