转发器选项页面中的转发器 - 从第一个转发器循环中获取数据

时间:2016-12-15 13:31:10

标签: wordpress if-statement while-loop advanced-custom-fields

下面的图片和代码应该是sumarise

image

基本上我希望文档链接显示在子转发器字段中的帖子对象页面上。我设法让代码在没有子转发器的情况下工作(仅限帖子对象),但这意味着文档只能在一个页面上显示...这不是理想的,因为客户希望文档可以在多个页面上访问 - 以及在组织文档方面更加用户友好(他们经常添加和删除文档)

<?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; 

这是正常的 - 它正在计算主页的两个实例。

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) {

这是代码开始动摇的地方 - 我想回到父转发器并在页面上显示相应的类别 - 但由于它是父循环中的父循环,它无限循环(我相信...或者至少页面超时501错误!)

      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; ?>

我已尝试休息并返回,但这意味着丢失$ post_object数据......任何帮助都将非常感激:)

0 个答案:

没有答案