Support

Account

Home Forums General Issues Order by nested repeater field in custom post type

Unread

Order by nested repeater field in custom post type

  • I am trying to order a nested repeater field by lowest total to highest but my issue is that it is grouping results by the custom post type eg:

    100
    200
    50
    70

    instead of

    50
    70
    100
    200

    How can I make it order by all the combined totals and not group it by custom post type record?

    <?php
    function my_featured_where($where)
    {
        $where = str_replace("meta_key = 'plans_$", "meta_key LIKE 'plans_%", $where);
        return $where;
    }
    add_filter('posts_where', 'my_featured_where');
    
    $featured_args = array(
        'post_type' => 'insurer',
        'posts_per_page' => - 1,
        'meta_key' => 'plans_$_plan_featured',
        'meta_value' => 1
    );
    $featured_insurers = new WP_Query($featured_args);
    ?>
    
    <?php $i = 1;
    while ($featured_insurers->have_posts()): $featured_insurers->the_post(); ?>
    <?php while (have_rows('plans')): the_row();
            if (get_sub_field('plan_featured') == 1):
    ?>
    <?php while (have_rows('plan_details')): the_row();
                    // sub fields here used to do calculations and get a result
                    $number = $_GET['number'];
                    $result = $number * get_sub_field( 'calc_field' );
    ?>
    <?php endwhile; ?>
    
    <!--This is where the ordered result should be-->
    
        <div>
        <?php echo $result; ?>   
        </div> 
    
    <!--end results  -->
          
    <?php endif; ?>
    <?php endwhile; ?>
    <?php $i++; endwhile; wp_reset_postdata(); ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.