Support

Account

Home Forums Add-ons Repeater Field Repeater field with IF/ELSE based on sub_field value Reply To: Repeater field with IF/ELSE based on sub_field value

  • Thank you for the time to look over the code.

    My initial goal was to show all the CPTs and Posts, on one page, sorted by date.

    But, I’ve never updated $args within a loop… so, heading this direction of showing rows of each type.

    My original logic for this was:

        $my_post_types = array( 'auctions', 'liquidations', 'inventory',  'post' );
    
        // set args for ALL posts
        $args = array(
            'post_type'     => $my_post_types,
            'orderby'       => 'date',
            'order'         => 'DESC',
            'post_status'   => 'publish',
        );
        
        Now we loop through posts (while loop)
    
        IF 'post_type == auctions' 
            change number_posts to $args from get_sub_field('items_per_row')
            get_template_part( 'template-parts/card', 'auction' );  
    
        IF 'post_type == liquidations' 
            change number_posts to $args from get_sub_field('items_per_row')
            get_template_part( 'template-parts/card', 'liquidations' );  
    
        IF 'post_type == inventory' 
            change number_posts to $args from get_sub_field('items_per_row')
            get_template_part( 'template-parts/card', 'inventory' );  
    
        IF 'post_type == post' 
            add 'cat => 304' to $args 
            change number_posts to $args from get_sub_field('items_per_row')
            and get_template_part( 'template-parts/card', 'studies' );  
    

    Since it was to be sorted by date, I wouldn’t need to setup the fields like I have now (so they can re-order them). I just need to allow them to choose the qty of posts shown for each type, let the loop sort by date.

    Any thoughts on this approach?