Support

Account

Home Forums Add-ons Repeater Field date repeater sorting for CPT

Unread

date repeater sorting for CPT

  • Hello
    I have a CPT with repeater.
    i want to get all dates of a CPT by repeater date order of all posts.

    post1
    17.01.19
    post 3
    28.12.18
    post 2
    27.12.18
    post 4
    20.12.18
    post 3
    08.12.18

    the results i”m getting with the code bellow.
    is close but not what i need..

    post1
    17.01.19

    post 2
    30.11.18
    post 2
    27.12.18

    post 3
    08.12.18
    post 3
    28.12.18

    post 4
    20.12.18

    how to make it sort by date for all posts and not internal for each post?

    this is my code:

    <?php 
    	$scheduled = new WP_Query(array(
    		'post_type' => 'repertoire',
    		'posts_per_page' => 12,
    		'order' => 'DESC',
    	));
      
      if ( $scheduled->have_posts() ) : 
        ?>
    <div class="single-repertoire--main-all">
    	<ul>
    	<?php while( $scheduled->have_posts() ) : $scheduled->the_post() ?>
               
            
    <?php 
    $repeater = get_field('dates');
    $order = array();
    $now = strtotime("now");
    
    foreach( $repeater as $i => $row ) {
    	$order[$i] = strtotime($row['show_date']);
    }
    
    array_multisort( $order, SORT_ASC, $repeater );
    
    if( $repeater ): ?>
        <?php 
        foreach( $repeater as $i => $row ): 
       
       $theDate = strtotime(str_replace('.', '-', $row['show_date']));
    
       if($theDate > $now){
           
       $date = $row['show_date'];
       $date = new DateTime($date);
       ?>
    
    	<li class="item">
    	<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    	<br>
    		<?php echo $date->format('d.m.y'); ?>
    	</li>
    
        <?php 
       }
    endforeach; ?>
      <?php endif; ?>
    
            <?php endwhile ?>
        <?php else : ?>
        <?php endif ?>
        <?php wp_reset_postdata(); ?>
    </ul>
    </div><!-- single-repertoire--main-all -->

    Thank you

Viewing 1 post (of 1 total)

The topic ‘date repeater sorting for CPT’ is closed to new replies.