Support

Account

Home Forums Add-ons Repeater Field Sort posts by ACF repeater field using multidimensional array

Unread

Sort posts by ACF repeater field using multidimensional array

  • Hello,

    I found an amazing code which can help me do exactly what i want !
    But the problem is that i want to show a post_object ‘lieu_evenement’ nested in a repeater field and I can’t find the way to do that, anyone ?

    As of now, it bug the script…

    Thanks

    
      $post_data = array();
      $args = array(
          'post_type'         => 'spectacles',
          'posts_per_page'    => -1,
      );
    
      $query = new WP_Query( $args );
      if ( $query->have_posts() ) 
      {
          while ( $query->have_posts() ) 
          {
              $query->the_post();
    
              if( have_rows('evenement') ):
                  while ( have_rows('evenement') ) : the_row();
                      {
                          $post_data[] = array(
                            'title' => get_the_title(),
    			'permalink' => get_the_permalink(),
                            'date_heure_debut'  => get_sub_field('date_heure_debut'),
    			'date_heure_fin'  => get_sub_field('date_heure_fin'),
    			'lieu'  => get_sub_field('lieu_evenement'),
                          );
                      }
                  endwhile;
              endif;
          }
      }
    
      function subval_sort( $a, $b )
      {
          if ( $a['date_heure_debut'] == $b['date_heure_debut'] )
              return 0;
          return $a['date_heure_debut'] < $b['date_heure_debut'] ? -1 : 1;
      }
      
      usort( $post_data, 'subval_sort' );
      
      foreach ( $post_data as $post ) 
      {?>
    	<?php echo $post['date_heure_debut'];?>
    	<?php echo $post['date_heure_fin'];?>
    	<a href="<?php echo $post['permalink'];?>" title="<?php echo $post['title'];?>">
    	<?php echo $post['title'];?>
    	</a>
    	<?php echo $post['lieu'];?>
    	<br/>
    
Viewing 1 post (of 1 total)

The topic ‘Sort posts by ACF repeater field using multidimensional array’ is closed to new replies.