this might be a bit complicated to explain so bare with me (couldn't even summarise it in the topic.) the image and code below should summarise
Essentially I want the document link to display on the post object pages within the sub-repeater field. I've managed to get the code working without a sub-repeater (post object only) but that means the document can only be displayed on one page... which isn't ideal as the client wants the documents accessible on multiple pages - as well as being more user friendly in regards to organising documents (they add and remove documents frequently)
<?php if ( have_rows('documents2', 'option') ) :
$currentPageID = $post->ID;
$countCheck = 0;
while ( have_rows('documents2', 'option') ) : the_row();
if ( have_rows('document_pages') ) :
while ( have_rows('document_pages') ) : the_row();
$post_object = get_sub_field('document_page');
if ($post_object->ID == $currentPageID) {
$countCheck++;
}
endwhile;
endif;
endwhile;
This is working properly - it's counting both instances of homepage.
if($countCheck > 0):
?>
<div class="documents">
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-8 col-md-offset-2">
<h2 class="text-center">Documents</h2>
<?php
$documentCategories = array();
while ( have_rows('documents2', 'option') ) : the_row();
if ( have_rows('document_pages') ) :
while ( have_rows('document_pages') ) : the_row();
$post_object = get_sub_field('document_page');
if ($post_object->ID == $currentPageID) {`
This is where the code begins to falter - I want to go back to the parent repeater and display the respective category on the page - but as it's a parent loop within a parent loop it loops infinitely (i believe... or at least the page times out with a 501 error!)
if ( have_rows('documents2', 'option') ) :
while ( have_rows('documents2', 'option') ) : the_row();
$terms = get_sub_field('document_category2');
if( $terms ):
foreach( $terms as $term ):
$tag = $term->name;
echo $tag;
endforeach;
endif;
endwhile;
endif;
}
endwhile;
endif;
endwhile;
?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
I've tried a break and return but it means losing the $post_object data... any help would be much appreciated :)
Aucun commentaire:
Enregistrer un commentaire