Поле ACF Repeater и проверка пользовательского повторителя в шаблоне архива WordPress выводит данные дважды - PullRequest
0 голосов
/ 03 марта 2020

Это страница архива, которую мне нужно проверить, вошел ли пользователь в систему, а затем находятся ли его продукты (в повторителе ACF) в списке сообщений о прошивке (oop) (в этом архиве). Встроенное ПО CPT имеет поле отношения ACF к своим продуктам.

У меня есть 2 проблемы: повторение заголовка примечаний к программному обеспечению; архивные сообщения выводятся дважды.


    <h1>Firmware Updates</h1>

    <?php $current_user = wp_get_current_user(); ?>
    <h3 style="margin-bottom: 6px;">Welcome, <?php echo $current_user->user_firstname; ?>!</h3>
    <p>Your registered product software and updates are listed below.<br/>
    Need to register another product on your account? Please fill out a <a data-fancybox href="#updateaccount">request form</a>.</p>

    <?php // Software notes
        if( have_rows('products', $userID) ): ?>
        <?php while( have_rows('products', $userID) ): the_row();

            $product = get_sub_field('product'); //get repeater post object

            if ($product): 
                $productpost = $product; 
                setup_postdata( $productpost ); ?>

            <?php //while there are software update posts
                while ( have_posts() ) : the_post(); ?>
                <?php if (!in_category( 'archive' )){ ?>

                <?php // Get product update product_relationship
                    $relationship = get_field('product_relationship');
                    if( $relationship ):
                        $i = 0;

                        foreach( $relationship as $product) : ?>

                        <?php //if user product ID equals firmware relationship ID
                            if ( $productpost->ID === $product->ID){ 

                                $productID = $product->ID;
                                $note = get_field('notes');

                                if ($note){ ?>
                                    <div class="notes clear">

                                    <?php if ($i = 1){?>
                                        <h3>Software Notes</h3>
                                    <?php } ?>

                                    <?php echo $note;?>

                                    </div>
                                <?php } ?>
                        <?php } ?>

                    <?php endforeach; ?>
                <?php endif; //end product_relationship ?>
                <?php } //end check for archive ?>
            <?php endwhile; ?>
            <?php wp_reset_postdata(); //reset user productpost setup ?>
            <?php endif; ?>
        <?php endwhile; ?>
    <?php endif; ?>


        <section class="body">  
            <h3>Manuals & Support Files</h3>

            <article class="updates">
                <h4>User Documentation</h4>
                    <ul>
                    <?php if( have_rows('products', $userID) ): ?>
                        <?php while( have_rows('products', $userID) ): the_row();  $post_object = get_sub_field('product'); 
                            if ($post_object): ?>
                            <?php $post = $post_object; setup_postdata( $post ); ?>

                                <!-- !User Guides [edit: Product]-->
                                <?php get_template_part( 'template-parts/firmware-user-guides' ); ?>

                            <?php wp_reset_postdata(); ?>
                            <?php endif; //$post_object?>
                        <?php endwhile; endif; //end if have_rows?>

                        <!-- !SSH Instructions [edit: Options Page]-->
                        <?php get_template_part( 'template-parts/firmware-ssh' ); ?>
                    </ul>

                    <!-- !APP Notes [edit: Options Page]-->
                    <?php get_template_part( 'template-parts/firmware-app-notes' ); ?>
            </article>
        </section>

        <h1 style="margin-bottom: -20px;">Software Downloads</h1>

        <?php // Get products user is registered for
            if( have_rows('products', $userID) ): ?>
            <?php while( have_rows('products', $userID) ): the_row();
                $product = get_sub_field('product'); //get repeater post object
                if ($product): 
                    $productpost = $product; 
                    setup_postdata( $productpost );
                    $i = 0; ?>

                <?php //while there are software update posts
                    while ( have_posts() ) : the_post(); ?>

                    <?php // Get product update product_relationship
                        $relationship = get_field('product_relationship');
                            if( $relationship ): ?>
                                <?php foreach( $relationship as $product): ?>

                                    <?php //if user product ID equals software relationship ID
                                        if ( $productpost->ID === $product->ID){ 
                                            $productID = $product->ID; ?>

                                            <?php if (!in_category( 'archive' )){ ?>                        
                                                <article class="updates">
                                                    <?php get_template_part( 'template-parts/product-updates' ); ?>
                                                    <?php get_template_part( 'template-parts/firmware-sdp' ); ?>
                                                    </div>
                                                </article>
                                            <?php } ?>

                                    <?php } ?>

                                <?php endforeach; ?>
                    <?php endif; //end product_relationship ?>
                <?php endwhile; ?>

                <?php wp_reset_postdata(); //reset user productpost setup ?>

                <?php endif; ?>
            <?php endwhile; ?>

        <?php endif; ?>
            <?php //rewind_posts(); ?>
        <?php //reset_rows(); ?>

    <h1>Archive</h1>
    <?php if( have_rows('products', $userID) ): 
        while( have_rows('products', $userID) ): the_row();
            $product = get_sub_field('product'); //get repeater post object
            if ($product): 
                $productpost = $product; 
                setup_postdata( $productpost ); ?>

            <?php //while there are software update posts
                while ( have_posts() ) : the_post();
                 if (in_category( 'archive' )){  ?>

                <?php // Get product update product_relationship
                    $relationship = get_field('product_relationship');
                    if( $relationship ): ?>
                        <?php foreach( $relationship as $product): ?>

                        <?php //if user product ID equals software relationship ID
                            if ( $productpost->ID === $product->ID){ 
                                $productID = $product->ID; 
                                echo $post->ID;?>

                                <div class="accordion updates">
                                    <header>
                                        <h2><?php the_title(); ?></h2>
                                        <?php if ( get_field('release') ){ ?>
                                            <span>Released <?php the_field('release'); ?></span>
                                        <?php } ?>
                                    </header>
                                    <div class="body">
                                        <?php if ( get_field('notes') ){ ?>
                                            <h3>Software Notes</h3>
                                            <?php the_field('notes'); ?>
                                        <?php } ?>
                                        <?php get_template_part( 'template-parts/product-updates-archive' ); ?>
                                        <?php get_template_part( 'template-parts/firmware-sdp' ); ?>

                                        <h4>User Documentation</h4>
                                        <ul>
                                            <!-- !User Guides Archive[edit: Product]-->
                                            <?php get_template_part( 'template-parts/firmware-user-guides-archive' ); ?>
                                        </ul>
                                    </div>
                                </div>

                        <?php } ?>

                        <?php endforeach; ?>
                <?php endif; //end product_relationship ?>

                <?php } //end check for archive ?>
                <?php endwhile; ?>

            <?php //rewind_posts(); ?>

            <?php wp_reset_postdata(); //reset user productpost setup ?>

            <?php endif; ?>
        <?php endwhile; endif;?>


<?php } //end if user logged in?>```

[enter image description here][1]


  [1]: https://i.stack.imgur.com/4qsp3.jpg
...