Support

Account

Home Forums Front-end Issues Problem on order post after save

Unread

Problem on order post after save

  • Hello i’ve create a custom plugin using ACF to display a TV guide but i have a problem.

    If actually have this post with this time on list:

    10.00 – 15.00
    15.01 – 16.00
    16.01 – 16.30
    16.31 – 19.00

    If i try to create and save new post with this setting 15.30 -15.59 after save i not display the post in correct order (so on second on list) but display as first post.

    <?php
    /* Template Name: Palinsesto */
    
    //We need jQeury UI for Tabs on this page. 
    
    add_action('wp_enqueue_scripts',function() {
        //wp_enqueue_style( 'jquery-ui' );
        wp_enqueue_script( 'jquery-ui-tabs' );
    });
    
    get_header();
    
    function get_allShows($args = array()) {
        //if arguments are not in array; 
        if(!is_array($args)) return; 
    
        $args = array_merge(array('post_type' => 'palinsesto','post_status' => 'publish', 'posts_per_page' => -1), $args);
    
        
    
        return get_posts($args);
    
    }
    
    function get_shows_on_daytime($day = 'monday', $time_interval='') {
    
        $time_intervals = array('primo-matino','mattino','mezzogiorno','pomeriggio','sera','notte');
        $trans_week_italian = array(
            'monday'    => 'lunedi',
            'tuesday'   => 'martedi',
            'wednesday' => 'mercoledi',
            'thursday'  => 'giovedi',
            'friday'    => 'venerdi',
            'saturday'  => 'sabato',
            'sunday'    => 'domenica',
        );
    
        // If someone tricking with us. 
        if(!array_key_exists($day, $trans_week_italian)) {
            return false;
        }
    
        //check if time_interval is correct 
        if(empty($time_interval) || !in_array($time_interval, $time_intervals)) {
            return false;
        }
    
        $args = array(
                    'meta_key'  => 'ora_inizio',
                    //'meta_type' => 'DATETIME',
                    'orderby'   => 'meta_value_num',
                    'order' => 'ASC',
                    'meta_query' => array(
                        'relation' => 'AND',array('key'       => 'giorno_programmazione',   'value'     => '"'.$trans_week_italian[$day].'"',   'compare'   => 'LIKE',),
                        'relation' => 'AND',array('key'       => 'fascia_di_programmazione','value'     => '"'.$time_interval.'"',              'compare'   => 'LIKE',),
                    )
            ); 
         
        $shows = get_allShows($args);
        
        ob_start();
    
        if(!empty($shows)) {
            foreach($shows as $show) {
                //Ending Shows Results template
            ?>
                <div class="show_item">
    				<ul>
                    <li class="timings"><?= get_field('ora_inizio',$show->ID); ?> - <?= get_field('ora_fine',$show->ID); ?></li>
                    <li class="show_title" style="font-family: Georgia, Times, 'Times New Roman', serif;"><?= $show->post_title; ?><br /><span class="conductor_name"><?php if( get_field('conduttore', $show->ID) ) :  echo get_field('conduttore', $show->ID);  endif; ?></span></li>
                        <?php if( $programs =  get_field('archivio_programma',$show->ID) ) : 
                                    if(is_array($programs)) {
                                        $link = get_category_link($programs[0]);
                                    } else if (is_int($programs) && $programs > 0) {
                                        $link = get_category_link($programs);
                                    } else {
                                        $link = '#';
                                    } ?>
                             <li class="archivio-link">
                                <a data-id="<?php echo $show->ID ?>"  style="font-family: Georgia, Times, 'Times New Roman', serif;" href="<?php echo $link; ?>"> Guarda l'Archivio </a>
                             </li>
                        <?php endif; ?>
                   
    				<ul>
                </div>
            <?php }    
        }
    
        return ob_get_clean();
    }
    
    function isCurrentActiveTime($startTime = "7:00 am",$endTime = "11:59 pm") {
    
        $current_time = date('h:i a',current_time('timestamp'));
    
        $rightNow = DateTime::createFromFormat('H:i a', $current_time);
        $date2 = DateTime::createFromFormat('H:i a', $startTime);
        $date3 = DateTime::createFromFormat('H:i a', $endTime);
    
        if ($rightNow > $date2 && $rightNow < $date3) {
    
            return true;
        }
        return false;
    }
    
    ?>
    <div class="td-main-content-wrap">
        <div class="td-container <?php echo $td_sidebar_position; ?>">
            <div class="td-crumb-container">
                <?php echo td_page_generator::get_page_breadcrumbs(get_the_title()); ?>
            </div>
            <div class="td-pb-row">
                <?php
                switch ($loop_sidebar_position) {
                    default:
                        ?>
                           <!-- <div class="td-pb-span8 td-main-content" role="main">
                                <div class="td-ss-main-content">        -->
                                <div class="td-pb-span12 td-main-content" role="main">
                                <?php
                                    if (have_posts()) {
                                        while ( have_posts() ) : the_post();
                                            ?>
                                            <div class="td-page-header">
                                                <h1 class="entry-title td-page-title">
                                                    <span><?php the_title() ?></span>
                                                </h1>
                                            </div>
                                            <div class="td-page-content">
                                           <?php the_content();
                                        endwhile;//end loop
                                    }
                                ?>
                                  
            <div id="tabs" class="palinsesto">
                <ul class="tabNavigation">
                    <li><a style="font-family: Georgia, Times, 'Times New Roman', serif;" href="#monday"><?php _e( 'Monday'); ?></a></li>
                    <li><a style="font-family: Georgia, Times, 'Times New Roman', serif;" href="#tuesday"><?php _e( 'Tuesday'); ?> </a></li>
                    <li><a style="font-family: Georgia, Times, 'Times New Roman', serif;" href="#wednesday"><?php _e( 'Wednesday'); ?>   </a></li>
                    <li><a style="font-family: Georgia, Times, 'Times New Roman', serif;" href="#thursday"><?php _e( 'Thursday'); ?>    </a></li>
                    <li><a style="font-family: Georgia, Times, 'Times New Roman', serif;" href="#friday"><?php _e( 'Friday'); ?>      </a></li>
                    <li><a style="font-family: Georgia, Times, 'Times New Roman', serif;" href="#saturday"><?php _e( 'Saturday'); ?>    </a></li>
                    <li><a style="font-family: Georgia, Times, 'Times New Roman', serif;" href="#sunday"><?php _e( 'Sunday'); ?>      </a></li>
                </ul>
    
                <?php foreach(array('monday','tuesday','wednesday','thursday','friday','saturday','sunday') as $key => $day): ?>
                <div id="<?=$day?>" class="subtab">
                    
                    <ul class="orarigiorno">
    				<ul>
    				<li class="day_present extra"> 
                        <div class="first"><?= date_i18n('j',strtotime($day.' this week')); ?></div>
    					<div class="second"><?= date_i18n('F',strtotime($day.' this week')); ?></div>
                    </li>
    				</ul>
                      <li><a style="color:#333" href="#<?=$day?>-primo-mattino" class="tablinks <?= isCurrentActiveTime('7:00 am','10:00 am')? 'active' : '' ?>">07.00 / 10.00</a></li>
                      <li><a style="color:#333" href="#<?=$day?>-mattino" class="tablinks <?= isCurrentActiveTime('10:00 am','1:00 pm')? 'active' : '' ?>">10.00 / 13.00</a></li>
                      <li><a style="color:#333" href="#<?=$day?>-mezzogiorno" class="tablinks <?= isCurrentActiveTime('1:00 pm','4:00 pm')? 'active' : '' ?>">13.00 / 16.00</a></li>
                      <li><a style="color:#333" href="#<?=$day?>-pomeriggio" class="tablinks <?= isCurrentActiveTime('4:00 pm','7:00 pm')? 'active' : '' ?>">16.00 / 19.00</a></li>
                      <li><a style="color:#333" href="#<?=$day?>-sera" class="tablinks <?= isCurrentActiveTime('7:00 pm','10:00 pm')? 'active' : '' ?>">19.00 / 22.00</a></li>
                      <li><a style="color:#333" href="#<?=$day?>-notte" class="tablinks <?= isCurrentActiveTime('10:00 pm','11:59 pm')? 'active' : '' ?>">22.00 / 00.00</a></li>
                    </ul>
    
                            <div id="<?=$day?>-primo-mattino" class="tabcontent"><p><?= get_shows_on_daytime($day,'primo-matino'); ?></p></div>
                            <div id="<?=$day?>-mattino" class="tabcontent"><p><?= get_shows_on_daytime($day,'mattino'); ?></p> </div>
                            <div id="<?=$day?>-mezzogiorno" class="tabcontent"><p><?= get_shows_on_daytime($day,'mezzogiorno'); ?></p></div>
                            <div id="<?=$day?>-pomeriggio" class="tabcontent"><p><?= get_shows_on_daytime($day,'pomeriggio'); ?></p></div>
                            <div id="<?=$day?>-sera" class="tabcontent"><p><?= get_shows_on_daytime($day,'sera'); ?></p></div>
                            <div id="<?=$day?>-notte" class="tabcontent"><p><?= get_shows_on_daytime($day,'notte'); ?></p></div>        
                </div>
                <?php endforeach; ?>  
            </div>
        </div>
                                </div>
                            </div>
                        <!--    <div class="td-pb-span4 td-main-sidebar" role="complementary">
                                <div class="td-ss-main-sidebar">
                                    <!--?php get_sidebar(); !--?>
                                </div>
                            </div>  !-->
                        <?php
                        break;
                }
                ?>
         <!--   </div> --><!-- /.td-pb-row -->
        </div> <!-- /.td-container -->
    </div> <!-- /.td-main-content-wrap -->
    
    <style>
        .subtab .orarigiorno li.ui-state-default{
            padding: 0 !important;
             border:1px solid transparent;
        }
        .subtab .orarigiorno li.ui-state-default a {
            padding: 0.72em 1.5em;
        }
        .subtab .orarigiorno li.ui-state-active a {
            background-color: #e29c04;
        }
        .palinsesto .tabNavigation {
            text-align:center;
            padding:0 !important;
            margin:auto;
        }
        .palinsesto .tabNavigation li {
            float:none !important;
            display:inline-block;
               
        }
    
        
        #tabs .tabNavigation li {
            border-radius: 0px;
            padding: 0 !important;
            margin:0 5px;
            text-transform: uppercase;
            border:1px solid transparent;
        }
        #tabs .tabNavigation li .ui-tabs-anchor {
           padding: .72em 1.5em;
        }
        ul.orarigiorno {
            background-color: #0e344b !important;
            padding: 13px 10px !important;
        }
        .ui-widget.ui-widget-content {
            border: 0px;
            padding: 0px !important;
        }
        .orarigiorno li:nth-child(2){
            margin-left: 62px !important;
        }
        .orarigiorno{
            margin-top: 35px !important;
            border-radius: 0px !important;
        }
        .first{
            color: #fff;
            font-size: 49px;
        }
        .second{
            color: #fff;
        }
        .extra{
            margin: 26px 0px 0px 18px !important;
        }
        .orarigiorno li.ui-state-default{
            padding: 3px 12px !important;
            margin-right: 25px !important;
            background: #fff !important;
            border-radius:0px !important;
        }
        .show_item ul li {
            display:inline-block;
            list-style: none;
        }
        .show_item ul{
            margin-left: 10%;
        }
        .show_item ul .timings{
            background: #0e344b;
            color: #fff;
            padding: 12px 21px;
        }
    
        @media only screen and (max-width : 1140px){ 
            #tabs .tabNavigation li {
                border-radius: 0px;
                padding: 3px 14px;
                margin-right: 15px;
                text-transform: uppercase;
            }
            .extra {
                margin: 26px 0px 0px 6px !important;
            }
            .orarigiorno li.ui-state-default {
                padding: 3px 11px !important;
                margin-right: 14px !important;
                background: #fff !important;
                border-radius: 0px !important;
            }
        }
    
        @media only screen and (max-width : 1024px) {
            #tabs .tabNavigation li {
                border-radius: 0px;
                padding: 3px 14px;
                margin-right: 9px;
                text-transform: uppercase;
                font-size: 11px;
            }
            .extra {
                margin: 26px 0px 0px 2px !important;
            }
            .orarigiorno li:nth-child(2) {
                margin-left: 31px !important;
            }
            .orarigiorno li.ui-state-default {
                padding: 3px 5px !important;
                margin-right: 10px !important;
                background: #fff !important;
                border-radius: 0px !important;
            }
            ul.orarigiorno li a {
                font-size: 11px !important;
            }
        }
    
        @media only screen and (max-width : 767px) {
            #tabs .tabNavigation li {
                width:100%;
            }
            .orarigiorno li{
                width:100%
            }
            .orarigiorno li:nth-child(2){
                margin-left: 0px !important;
            }
            .show_item ul .timings {
                background: #0e344b;
                color: #fff;
                padding: 7px 11px;
            }
            .show_item ul{
                margin-left: 0px !important;
            }
        }
        .show_item ul li {
            display: inline-block;
            list-style: none;
            font-size: 14px;
            vertical-align: middle;
        }
        .archivio-link {
            padding: 10px 15px;
            background-color: #0e344b;
        }
        .archivio-link a {
            color:#fff;
        }
        /*#monday-primo-mattino{
            padding:0px !important;
        }*/
    
    </style>
    
    <script>
    jQuery(document).ready(function( $ ){
        $('#tabs,.subtab').tabs();
        var tabContainers = jQuery('div#tabs > div');
       
        jQuery('div#tabs ul.tabNavigation a').on('click',function (ev) {
                tabContainers.hide().filter(this.hash).show();
                jQuery('div#tabs ul.tabNavigation a').removeClass('selected');
                jQuery(this).addClass('selected');
                activeAnchor = this.hash;
                tabContainers.filter(this.hash).find('.orarigiorno li a.active').click();
                return false;
            }).eq((new Date().getDay() || 7) - 1).click();
    });
    
    </script>
        <?php
    get_footer();

    How can i fix this problem?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.