d2321
2/12/2020 - 1:19 PM

Query with ACF repeater and order by repeater array

<?php if ( have_rows($team_field) ) : $rel_t = array(); while( have_rows($team_field) ) : the_row(); ?>			
    <?php $rel_t[] = get_sub_field('person'); ?>		
<?php endwhile; endif; ?>
<?php
    $args = array(
        'showposts' => -1,
        'post_type' => 'zespol',
        //'post__not_in' => array(get_the_ID())
    );
    if($rel_t) {
        $args['post__in'] = $rel_t;
        $args['showposts'] = -1;
        $args['orderby'] = 'post__in';
    }            
    $query = new WP_Query( $args );
?>

<div class="row">
    <?php if( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
        <div class="col-md-3">
            <div class=""><img src="<?php echo _themename_get_thumb_image(); ?>" alt=""></div>
            <div class=""><?php the_title(); ?></div>
            <div class=""><?php the_field('info'); ?></div>
            <div class=""><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
        </div>
    <?php endwhile; endif; wp_reset_query(); ?>
</div>
<div class="container mb-md-10">
    <h2 class="title-40 text-center mb-md-10"><?php the_field('blog_title'); ?></h2>
    
    <?php
        $args = array(
            'showposts' => 3,
        );
		
		// acf - object field, type ID, allow to multiple posts
		if(get_field('blog')) {
			$args['post__in'] = get_field('blog');
			$args['showposts'] = -1;
			$args['orderby'] = 'post__in';				
		}
        
        $query = new WP_Query( $args );
    ?>

    <div class="row">    
        <?php if( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
            <div class="col-md-4 col-card-blog">
                <?php include (locate_template( 'parts/card-blog.php' )); ?>
            </div>
        <?php endwhile; endif; wp_reset_query(); ?>
    </div>
    
</div>