
Could somebody please help me to order the following query by date of the subfield ‘beginn’ :
With the following code it is ordered (only shown future dates), but it is gouped by posts.
But I would like to create a eventlist like an index of all posts/ travels ordered by all beginning dates…
(Each post is a travel with several beginning and end -dates and repeater like t_block_beginn ; t_block_ende ; t_block_price ect.)
<?php while ( have_posts() ): the_post(); ?>
<?php
// check if the repeater field has rows of data
if( have_rows('t_block') ):
$i = 0;
// loop through the rows of data
while ( have_rows('t_block') ) : the_row();
$now = strtotime(date('Y-m-d', time()));
// I am assuming that your date is stored as 'Y-m-d'
// see strtotime php doc form more information
$end_time = strtotime(get_sub_field('beginn'));
if ($now > $end_time) {
// not in the future, go to the next row
continue;
}
$i++;
if( $i > 60 )
{ break; }
$date_beginn = DateTime::createFromFormat('Ymd', get_sub_field('beginn'));
$date_ende= DateTime::createFromFormat('Ymd', get_sub_field('ende'));
$preis= get_sub_field('preis');
$buchbar= get_sub_field('buchbar');
$sprache= get_sub_field('sprache');
$bemerkung= get_sub_field('bemerkung');
$garantiert= get_sub_field('gesichert');
// display a sub field value
echo '' . $date_beginn->format('d.m.Y') . ' - ';
echo '' . '-' . '';
echo '' . $date_ende->format('d.m.Y') . '';
echo ' ' ."[url=]post_id) . "'>";
echo get_the_title( $row->post_id ).' ';
echo "";
echo '' . $preis . ' € ';
echo '' . $sprache . ' ';
endwhile;
else :
endif; ?>
<?php endwhile; ?>
Hi @taro09
I’m afraid you need to use wpdb class for this case. This will allow you to query the repeater’s rows without looping through the posts. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/querying-the-database-for-repeater-sub-field-values/.
I hope this helps 🙂