Support

Account

Home Forums Add-ons Repeater Field Calendar by month with date repeater Reply To: Calendar by month with date repeater

  • Hi @trainsrenton

    After that, you can sort the data by using the array_multisort() function. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/. Here’s an example how to do it:

    $rows = ''; // The variable that holds the repeater result
    
    // vars
    $order = array();
    
    // populate order
    foreach( $rows as $i => $row ) {
    	
    	$order[ $i ] = $row['meta_value'];
    	
    }
    
    // multisort
    array_multisort( $order, SORT_ASC, $rows );
    
    $current_month = null;
    foreach( $rows as $row){
        $date = DateTime::createFromFormat('Ymd', $row['meta_value']);
        $month = $date->format('F');
        if( $current_month != $month ){
            echo $month . "\r\n";
            $current_month = $month;
        }
        echo $row['meta_value'] . "\r\n";
    }

    You can also get the post object by using the get_post() function like this:

    echo $row['meta_value'] . "\r\n";
    $thepost = get_post($row['post_id']);
    print_r($thepost);

    I hope this helps 🙂