Support

Account

Home Forums Front-end Issues Get Total of Matching Fields in Repeater Within Custom Query Reply To: Get Total of Matching Fields in Repeater Within Custom Query

  • Thank you for pointing me in the right direction! I was able to add those into an array, although within an extra associate array, with the below and just need to figure out how to add the similar indices, and add the counts and details.

    
    if( have_rows('flowers_count_list') ):
        
    
            // Loop through rows.
            while( have_rows('flowers_count_list') ) : the_row();
    
        $featured_posts = get_sub_field('flowers');
    
        if( $featured_posts ): ?>
        <?php foreach( $featured_posts as $post ): 
    
            // Setup this post for WP functions (variable must be named $post).
            setup_postdata($post); ?>
                <?php /*
                echo get_the_title( $post->ID );
                echo '( ';
                the_sub_field('flowers_count');
                echo ' )';
                */
    
                $flowers_count_list_full_array[] = [
                    'name'=> get_the_title( $post->ID ),
                    'count'=>get_sub_field('flowers_count'),
                    'details'=> get_the_title().' ('.get_sub_field('flowers_count').')',
                ];
                ?>
        <?php endforeach; ?>
        <?php 
        // Reset the global post object so that the rest of the page works correctly.
        wp_reset_postdata();
    
        endif;
            // End loop.
            endwhile;
    
            // No value.
            else :
                // Do something...
            endif;
    
    // Check rows exists.
        if( have_rows('hard_goods_count_list') ):
        
        //echo '<h3>Hard Goods List:</h3>';
    
            // Loop through rows.
            while( have_rows('hard_goods_count_list') ) : the_row();
    
        $featured_posts = get_sub_field('hard_goods');
    
        if( $featured_posts ): /*?>
        <ul>
        <?php foreach( $featured_posts as $post ): 
    
            // Setup this post for WP functions (variable must be named $post).
            setup_postdata($post); ?>
            <li>
    
                <?php 
                echo get_the_title( $post->ID );
                echo '( ';
                the_sub_field('hard_goods_count');
                echo ' )';
                ?>
            </li>
        <?php endforeach; ?>
        </ul>
    
        <?php*/ 
    
        // Reset the global post object so that the rest of the page works correctly.
        wp_reset_postdata();
        
    
        endif;
            // End loop.
            endwhile;
    
            // No value.
            else :
                // Do something...
            endif;
    
                echo '</div>';
            endwhile;
        echo '</div>';
        echo '<h3>Flowers List:</h3>';
        echo 'Filled Array!: <br/>';
        print_r($flowers_count_list_full_array);
    
        echo '<br/>Combined Array!: <br/>';
    
        $combined_flowers_count_list_full_array = $flowers_count_list_full_array;
            
        var_dump(array_merge($flowers_count_list_full_array));
    
            wp_reset_postdata();
        else :
            echo 'No posts found';
        endif;
        
        die();
    
    }