Support

Account

Home Forums General Issues Problem with ACF Date with Custom Post Type.

Unread

Problem with ACF Date with Custom Post Type.

  • Hello!
    I have problem with output date from ACF Date. I use Custom Post Type with ACF for trainings courses so I need correct date and hours.

    For example I have training inside post selected 15.06.2021 and 14:00 but in admin column print 14.06.2021 and 12:00? Why?

    I saw many solutions… but any nothing working. I used timezone and $date = DateTime::createFromFormat('Ymd', $date_string); but still not working. I use newest version of WP and ACF Pro.

    My code is below what wrong?

    function columns_trainings_data($column, $post_id) {
    
        $trainings = get_field('trainings');
    
        if ($column === 'title') {
            echo the_title();
    
        } elseif ($column == 'training-date') {
    
            echo $trainings['date'];
    
        } elseif ( $column === 'day') {
    
            switch ($trainings['day']) {
                case 'PON':
                    echo '<b>' . 'Poniedziałek' . '</b>';
                    break;
                case 'WT':
                    echo '<b>' . 'Wtorek' . '</b>';
                    break;
                case 'ŚR': 
                    echo '<b>' . 'Środa' . '</b>';
                    break;
                case 'CZW':
                    echo '<b>' . 'Czwartek' . '</b>';
                    break;
                case 'PT':
                    echo '<b>' . 'Piątek' . '</b>';
                    break;
                case 'SB':
                    echo '<b>' . 'Sobota' . '</b>';
                    break;
                case 'ND':
                    echo '<b>' . 'Niedziela' . '</b>';
                    break;
            }
           
        } elseif ($column === 'hour') {
    
            echo '<b>' . $trainings['hour'] . '</b>';
    
        } elseif ($column === 'place') {
    
            $address = $trainings['training_address'];
    
            if ($address['city'] && $address['street']) {
                echo '<b>' . $address['city'] . ', ' . $address['street'] . '</b>';
            } elseif ($trainings['virtual']) {
                echo '<b>' . 'Szkolenie online' . '</b>';
            } else {
                echo '<b>' . 'Brak danych' . '<b>';
            }
    
        } elseif ($column == 'type') {
    
            if ($trainings['type'] == 'periodic') {
                echo '<div style="border: 2px solid #FF510B; padding: 5px; width: 100px; background-color: #FF510B; color: white;">' . '<b>' . 'Okresowe' . '</b>' . '<div>';
            } else {
                echo '<div style="border: 2px solid #FF510B; padding: 5px; width: 100px;">' . '<b>' . 'Wstępne' . '</b>' . '<div>';
            }
    
        } elseif ($column == 'active') {
    
            date_default_timezone_set('Europe/Warsaw'); $date_now = date('d-m-Y') ;
            $date = $trainings['date'];
    
            if (strtotime($date) > strtotime($date_now)) {
                echo '<b style="color: green">' . 'Aktualne' . '</b>';
            } elseif (strtotime($date) == strtotime($date_now)) { 
                echo '<b style="color: darkgray">' . 'Dzisiaj' . '</b>';
            } else {
                echo '<b style="color: red">' . "Zakończone" . '</b>';
            }
    
        } else {
            //do nothing
        }
    }
    
    add_action('manage_training_posts_custom_column' , 'columns_trainings_data', 10, 2); 
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.