Support

Account

Home Forums Add-ons Repeater Field order acf repeater-field by datepicker in wp-query

Solving

order acf repeater-field by datepicker in wp-query

  • How can I sort repeater fields by datepicker within a wp-query and a category.

    This is my source:

    <ul class="program-list">
    <?php query_posts('cat=2'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    		
    	
    	<?php if( have_rows('program_repeater') ): ?>
    		<?php while( have_rows('program_repeater') ): the_row(); 
    			$dateDayNumber = date_i18n("d", strtotime(get_sub_field('program_repeater_date')));
    			$dateMonthNumber = date_i18n("m", strtotime(get_sub_field('program_repeater_date')));
    			$dateDayOrg = date_i18n("l", strtotime(get_sub_field('program_repeater_date')));
    			$dateDay = substr($dateDayOrg, 0, 2);
    			$dateTime = get_sub_field('program_repeater_time');
    			$specialEvent = get_sub_field('program_repeater_special');
    			$mainTitle = get_the_title();
    			$subTitle = get_field('sub_text');
    			$rowSeatsId = get_sub_field('program_repeater_rowseats_id');
    			?>
    			
    			<li>
    				<div class="specialEvent"><?php if( $specialEvent ): ?><?php echo $specialEvent; ?><?php else: ?>&nbsp;<?php endif; ?></div>
    				<div class="dateDayNumber"><?php echo $dateDayNumber; ?></div>
    				<div class="dateMonthNumber"><?php echo $dateMonthNumber; ?></div>
    				<div class="dateDay"><?php echo $dateDay; ?></div>
    				<div class="v-line-zick-zack"></div>
    				<div class="dateTime"><?php echo $dateTime; ?></div>
    				<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    					<div class="mainTitle"><?php echo $mainTitle; ?></div>
    					<div class="subTitle"><?php echo $subTitle; ?></div>
    				</a>
    				<a href="<?php the_permalink(); ?><?php echo "?id=" . $rowSeatsId; ?>" title="<?php the_title_attribute(); ?>">
    					<div class="ticket-link">Tickets kaufen</div>
    				</a>
    				<div class="clear"></div>
    			</li>
    			
    			
    		<?php endwhile; ?>
    	<?php endif; ?>
    	
    		
    <?php endwhile; endif; ?>
    <?php wp_reset_query(); ?>
    </ul>

    Thanks in advance

    Joe

  • Does somebody has any idea?

  • if you dont try to merge your posts into one list you could try this:

    <ul class="program-list">
    <?php query_posts('cat=2'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php
    $repeater = get_field('program_repeater');
    foreach( $repeater as $key => $row ) {
    		$thedate = $row['program_repeater_date']; 
    		$column_id[ $key ] = strtotime($thedate);
    	}
    array_multisort( $column_id, SORT_ASC, $repeater );
    	foreach( $repeater  as $row ){
    
    $dateDayNumber = date_i18n("d", strtotime(get_sub_field('program_repeater_date')));
    			$dateMonthNumber = date_i18n("m", strtotime(get_sub_field('program_repeater_date')));
    			$dateDayOrg = date_i18n("l", strtotime(get_sub_field('program_repeater_date')));
    			$dateDay = substr($dateDayOrg, 0, 2);
    			$dateTime = get_sub_field('program_repeater_time');
    			$specialEvent = get_sub_field('program_repeater_special');
    			$mainTitle = get_the_title();
    			$subTitle = get_field('sub_text');
    			$rowSeatsId = get_sub_field('program_repeater_rowseats_id');
    			?>
    			
    			<li>
    				<div class="specialEvent"><?php if( $specialEvent ): ?><?php echo $specialEvent; ?><?php else: ?>&nbsp;<?php endif; ?></div>
    				<div class="dateDayNumber"><?php echo $dateDayNumber; ?></div>
    				<div class="dateMonthNumber"><?php echo $dateMonthNumber; ?></div>
    				<div class="dateDay"><?php echo $dateDay; ?></div>
    				<div class="v-line-zick-zack"></div>
    				<div class="dateTime"><?php echo $dateTime; ?></div>
    				<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    					<div class="mainTitle"><?php echo $mainTitle; ?></div>
    					<div class="subTitle"><?php echo $subTitle; ?></div>
    				</a>
    				<a href="<?php the_permalink(); ?><?php echo "?id=" . $rowSeatsId; ?>" title="<?php the_title_attribute(); ?>">
    					<div class="ticket-link">Tickets kaufen</div>
    				</a>
    				<div class="clear"></div>
    			</li>
    <?php } ?>
    <?php endwhile; endif; ?>
    <?php wp_reset_query(); ?>
    </ul>

    If you try to merge them => you need to build a array first, order it, and echo it after that.

    try to adapt a solution like this or this

  • Alternatively, You will need to create a custom query using either the get_posts() or wp_Query and have the posts filtered by the date picker values as the meta_keys. But because you do not know the row number, you will have to create a custom function to change the standard ‘=’ to ‘LIKE’ in the query.

    Please see: https://support.advancedcustomfields.com/forums/topic/sort-posts-by-date-picker-in-repeater-field/

    I hope that helps

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘order acf repeater-field by datepicker in wp-query’ is closed to new replies.