Support

Account

Home Forums Add-ons Repeater Field Sort repeater field by nested field value

Unread

Sort repeater field by nested field value

  • So, I have a repeater field (press publications) that then has a sub-repeater (press links). I want to display all the links on the output sorted by the ‘publish_date’ field. So far I’ve been able to sort the sub repeater by the date field so that it always displays the most recent at the top, but I can’t seem to make it return each <li> item in order of date regardless of publication (‘press’ field parent). In other words, if I have 3 links under the Daily Mail and 3 links under The Sun, this will always return the 3 Daily Mail links (in date order) in a group, then The Sun links after. I would like it to return it like:
    Daily Mail link 1 (todays date),
    The Sun link 1 (yesterdays date),
    Daily Mail link 2 (two days ago)

    and so on. See below code:

    
      <?php if (have_rows('press')):?>
          <ul class="clear-list post-preview-list ajax-posts" id="main">
    		
    		  <?php while(have_rows('press')): the_row();
    		  $logo = get_sub_field('press_logo');
    		  $pubtitle = get_sub_field('publication');
    		  if( have_rows('press_links') ):
     	// loop through the rows of data
        while ( have_rows('press_links') ) : the_row();
    		  $link = get_sub_field('press_link');
    													
    		  if ($link):
    			  $title = $link['title'];
    			  $url = $link['url'];?>
    		  <li class="post drop-shadow">
    		  <article class="post-preview press-item">
    			  <a href=""><img />"></a>
    			
    			  <div class="press-info smaller">
                        <h2 class="post-title">
                            <a target="_blank">"><?php echo esc_html($title); ?></a>
                        </h2>
    				   <p class="txt-style-2">
                            <a href="/"><?php echo $pubtitle; ?></a> |
                            <time class="post-time"><?php the_sub_field('publish_date');?></time>
                        </p>
    			  </div>
    			  
    			  </article>
    		  </li>
    		
    		  <?php  endif; endwhile; endif;?>
    		  <?php endwhile; endif;?>
    	 
    	  </ul>
    
Viewing 1 post (of 1 total)

The topic ‘Sort repeater field by nested field value’ is closed to new replies.