lundi 5 octobre 2015

empty query breaks other queries

Hi I have a cpt query which displays 1 latest event based on date. It works fine - problem is when date is < today (theres no future events to display) this query is empty and also breaks other queries on site.

                                                        <?php
                                                    $today = date("Y-m-d");             
                                                    $argsmi = array('posts_per_page' => 1, 'post_type' => 'imprezy', 'orderby' => 'meta_value_num', 'order' => ASC,
                                                        'meta_query' => array(
                                                                            'relation' => 'OR',
                                                                            array(
                                                                               'key' => 'data_imprezy',
                                                                               'value' => $today,
                                                                               'compare' => '>=',
                                                                               'type' => 'datetime'
                                                                            ),
                                                                            array(
                                                                               'key' => 'data_imprezy_do',
                                                                               'value' => $today,
                                                                               'compare' => '>=',
                                                                               'type' => 'datetime'
                                                                            ))  

                                                    );

                                                    $temp = $wp_query;
                                                    $wp_query = null;
                                                    $wp_query = new WP_Query( $argsmi );
                                                    if ( $wp_query->have_posts() ) : ?>

                                                                        <?php while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>  

                                                                            <div class="singleevthumbdiv">

                                                                                <a href="<?php the_permalink(); ?>">

                                                                                                    <?php

                                                                                                        if ( has_post_thumbnail() ) {
                                                                                                            the_post_thumbnail('thumbnail', array('class' => 'singleevthumb'));
                                                                                                        }
                                                                                                        else {

                                                                                                        }

                                                                                                    ?>

                                                                                </a>

                                                                                <div class="cbmob"></div>

                                                                                <div class="datatitle">

                                                                                    <a href="<?php the_permalink(); ?>" class="singleevtitle"><?php the_titlesmall('', '...', true, '25') ?></a><div style="clear:both;"></div>

                                                                                    <?php $date = DateTime::createFromFormat('Ymd', get_field('data_imprezy')); ?>
                                                                                    <?php $datedo = DateTime::createFromFormat('Ymd', get_field('data_imprezy_do')); ?>

                                                                                    <span class="data">

                                                                                        <?php echo $date->format('d-m-Y'); ?>

                                                                                        <?php if( get_field('data_imprezy_do') ): ?>

                                                                                                - <?php echo $datedo->format('d-m-Y'); ?>

                                                                                        <?php endif; ?>

                                                                                    </span> 

                                                                                    <div style="clear:both;"></div>

                                                                                </div>

                                                                            </div>



                                                                        <?php endwhile; ?>                                              

                                                    <?php $wp_query = null; $wp_query = $temp; wp_reset_query(); ?>
                                                    <?php endif; ?> 



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire