Support

Account

Forum Replies Created

  • OK. figured it out.
    managed to change the dates to “pretty” and add the rest of the fields that i needed.
    the months name titles working… but i made them in a stupid way.
    maybe somebody can add a nice fix to it.
    hope it will help somebody as it helped me.

    
    <?php
    
    $repeater = get_field('vacation_repeater1');
    $order = array();
    $now = strtotime("now");
    $sortedDate = array();
    
    foreach( $repeater as $i => $row ) {
        $order[ $i ] = $row['start_date'];
    }
    
    array_multisort( $order, SORT_ASC, $repeater );
    
    foreach($repeater as $row){
    
        $theDate = strtotime(str_replace('/', '-', $row['start_date']));
    
        if($theDate > $now){
            $theMonth = substr($row['start_date'],4 ,2);
            if (!isset($sortedDate[$theMonth])){
                $sortedDate[$theMonth] = array();
            }
            array_push($sortedDate[$theMonth], $row);
        }
    }
    
    foreach($sortedDate as $theMonth => $theDates){
    	 //echo $theMonth . '<br/>';
    if($theMonth == 01) {
    	echo 'Jan <br/>';
    } elseif($theMonth == 02) {
    	echo 'February <br/>';
    } elseif($theMonth == 03) {
    	echo 'March <br/>';
    } elseif($theMonth == 04) {
    	echo 'April <br/>';
    } elseif($theMonth == 05) {
    	echo 'May <br/>';
    } elseif($theMonth == 06) {
    	echo 'June <br/>';
    } elseif($theMonth == 07) {
    	echo 'July <br/>';
    } elseif($theMonth == 08) {
    	echo 'August <br/>';
    } elseif($theMonth == 09) {
    	echo 'September <br/>';
    } elseif($theMonth == 10) {
    	echo 'October <br/>';
    } elseif($theMonth == 11) {
    	echo 'November <br/>';
    } elseif($theMonth == 12) {
    	echo 'December <br/>';
    }
    
    foreach($theDates as $theDate){
    	//echo $theDate['start_date']. '<br/>';
    	$date = $theDate['start_date'];
    	$date_tour = date_i18n("l, F j, Y", strtotime($date));
    	echo $date_tour. '<br/>';
    
    	echo $theDate['flight_to_time']. '<br/>';
    	echo $theDate['flight_back_time']. '<br/>';
    	echo $theDate['price_standart']. '<br/>';
    	echo $theDate['price_standart_plus']. '<br/>';
    	echo $theDate['air_company']. '<br/>';
    	echo '<br/><br/>';
    }//$theDate
    
    }//$theMonth
    
     ?>
    
  • Thank you James!
    It works as i needed!
    This will help a lot of ACF users.

    the only thing i changed is 3,2 into 4,2 at line $theMonth = substr($row['date_field_name'],4 ,2); cause my dates appear as 20160412.

    to finalize the code a question, how to echo the dates and title months to show as “pretty”?
    i used before $start_date_pretty = date_i18n( 'l, F j, Y', $start_date ); but i don’t see how i can use that in this working code.

    Thank you again

  • Thank you James for your replay.
    sorry but i need a different kind of sort.
    separate dates into months – so each month show its dates + month title.
    sample:

    March
    23/3/2016
    27/3/2016

    April
    12/4/2016
    17/4/2016

    also can you explain – echo $row['tr1_date1']; do i need to change it? cause i don’t get any results.

    Thank You.

  • Thank you James
    I have done the repeater sort. it sorts by date. and also hide the past dates…
    but i need to separate the dates into months and hide past months –
    this is the problem i couldn’t figure.

    the code i used so far.

    <?php
    // get repeater field data
    $repeater = get_field('vacation_repeater1');
    // vars
    $order = array();
    
    if( $repeater ):
    // populate order
    foreach( $repeater as $i => $row ) {
    	$order[ $i ] = $row['start_date'];
    }
    array_multisort( $order, SORT_ASC, $repeater );
    ?>
    	<?php foreach( $repeater as $i => $row ): ?>
    <?php
    	$end_date = get_sub_field('end_date');
    			$today = date('Ymd');
    	$get_startdate = $row['start_date'];
    	$start_date = (strtotime($get_startdate));
    //use $get_startdate to order, and $start_date_pretty to output your date
    	$start_date_pretty = date_i18n( 'l, F j, Y', $start_date );
     ?>
    
    <?php if($today <= $get_startdate ) { ?>
    
    <ul>
    <li class="flight_date_time">
    	<?php echo $start_date_pretty; ?>
    </li>
    <li class="flight_date_time">
    	<?php echo $row['end_date']; ?>
    </li>
    </ul>
    <div class="clear"></div>
    
    <?php } ?>
    
    	<?php endforeach; ?>
    <?php endif; ?>
Viewing 4 posts - 1 through 4 (of 4 total)