php 帖子Поискпонесколькимкастомфлдамвыгребаетпостыопределенноготипаитаксономиисопределеннымикастомфилд

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 帖子Поискпонесколькимкастомфлдамвыгребаетпостыопределенноготипаитаксономиисопределеннымикастомфилд相关的知识,希望对你有一定的参考价值。

<?php include('../../../wp-load.php'); ?>

<?php
    include('../../../../wp-load.php');
    
    $taxonomy_id = (int) $_GET['taxonomy'];
    $paged = 1;
    if(isset($_GET['paged'])){
        $paged = (int) $_GET['paged'];   
    }
    $search_query = array();
    
    
    $search = '';
    if(isset($_GET['search']) && strtolower($_GET['search']) != 'keyword, artist, title'){
        $search = esc_attr($_GET['search']);
    }
    
    if(!empty($search)){
        $search_query = array(
            'post_type' => array('exhibition', 'deste-prize', 'hydra'),
            'tax_query' => array(
                array(
                    'taxonomy' => 'exhibition-category',
                    'field' => 'id',
                    'terms' => $taxonomy_id
                )
            ),
            'meta_query' => array(
                'relation' => 'OR',
                array(
                    'key' => 'title',
                    'value' => $search,
                    'compare' => 'LIKE'
                ),
                array(
                    'key' => 'artist',
                    'value' => $search,
                    'compare' => 'LIKE'
                ),
                array(
                    'key' => 'keywords',
                    'value' => $search,
                    'compare' => 'LIKE'
                )    
            ),
            'posts_per_page' => -1,
        );
    }
    
    $query = array(
        'post_type' => array(),
        'tax_query' => array(
            array(
                'taxonomy' => 'exhibition-category',
                'field' => 'id',
                'terms' => $taxonomy_id
            )
        ),
        'meta_query' => array(),
        'posts_per_page' => -1,
    );
    
    $year = 0;
    if(isset($_GET['year'])){
        $year = (int) $_GET['year'];
    }
    
    if(isset($_GET['deste_prize']) && $_GET['deste_prize'] == 'on'){
        $query['post_type'][] = 'deste-prize';
    }
    if(isset($_GET['hydra']) && $_GET['hydra'] == 'on'){
        $query['post_type'][] = 'hydra';
    }
    if(!count($query['post_type'])){
        $query['post_type'] = array('exhibition', 'deste-prize', 'hydra');
    }
    
    if($year){
        $query['meta_query'][] = array(
            'key' => 'exhibition_year',
            'value' => $year,
            'type' => 'NUMERIC'
        );
    }
    if(isset($_GET['collection_pased']) && $_GET['collection_pased'] == 'on'){
        $query['meta_query'][] = array(
            'key' => 'collection_based',
            'value' => 1,
            'type' => 'NUMERIC'
        );
    }
    if(isset($_GET['events']) && $_GET['events'] == 'on'){
        $query['meta_query'][] = array(
            'key' => 'events',
            'value' => 1,
            'type' => 'NUMERIC'
        );
    }
    
    $q1_results = array();
    $q2_results = array();
    
    $q = new WP_Query($query);
    
    if($q->have_posts()){
        while($q->have_posts()){
            $q->the_post();
            $q1_results[] = get_the_ID();
        }
    }
    wp_reset_query();
    
    if(count($search_query)){
        $q2 = new WP_Query($search_query);
    
        if($q2->have_posts()){
            while($q2->have_posts()){
                $q2->the_post();
                $q2_results[] = get_the_ID();
            }
        }
        wp_reset_query();
    }
    
    if(count($search_query)){
        $results = array_intersect($q1_results, $q2_results);
    }
    else{
        $results = $q1_results;    
    }
?>
<div class="ajax-content">
    <?php
        if(count($results)):
            $final_query = array(
                'post_type' => $query['post_type'],
                'post__in' => $results,
                'posts_per_page' => 12,
                'paged' => $paged
            );
            
            $r = new WP_Query($final_query);
            
            if($r->have_posts()):
            
            echo '<div class="content-boxes">';
            
            while($r->have_posts()): $r->the_post();
                $exhibition_square_featured_image = get_field('exhibition_square_featured_image');
                $exhibition_type = get_field('exhibition_type');
                $exhibition_from_date = get_field('exhibition_from_date');
                $exhibition_to_date = get_field('exhibition_to_date');
    ?>
                <div class="box">
                    <?php if($exhibition_square_featured_image): ?>
                        <a href="<?php the_permalink(); ?>"><?php echo wp_get_attachment_image($exhibition_square_featured_image, 'past-shows-thumbnail'); ?></a>
                    <?php endif; ?>
                    <?php if(count($exhibition_type)): ?>
                        <span class="category"><?php echo implode(', ', $exhibition_type); ?></span>
                    <?php endif; ?>
                    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                    <?php if($exhibition_from_date && $exhibition_to_date): ?>
                        <?php
                            $exhibition_from_date = DateTime::createFromFormat('Ymd', $exhibition_from_date)->getTimestamp();
                            $exhibition_to_date = DateTime::createFromFormat('Ymd', $exhibition_to_date)->getTimestamp();
                            $difference = $exhibition_to_date - $exhibition_from_date;
                            $seconds_in_year = 31536000;
                            if($difference > $seconds_in_year){
                                printf('<span class="date2">%s-%s</span>', date('j.n.Y', $exhibition_from_date), date('j.n.Y', $exhibition_to_date));
                            }
                            else{
                                printf('<span class="date2">%s-%s</span>', date('j.n', $exhibition_from_date), date('j.n/Y', $exhibition_to_date));
                            }
                        ?>
                    <?php endif; ?>
                </div>
    <?php
            endwhile;
            
            echo '</div>';
            
            if(function_exists('custom_wp_pagenavi')){
                echo custom_wp_pagenavi(array('before' => '<div class="paging">', 'after' => '</div>', 'query' => $r));
            }
            
            endif;
            wp_reset_query();
        else:
    ?>
        <div class="content-boxes">
            <div class="box wide">
                <h3><?php _e('Not Found', 'base'); ?></h3>
                <p><?php _e('Sorry, but you are looking for something that isn\'t here.', 'base'); ?></p>
            </div>
        </div>
    <?php endif; ?>
</div>

以上是关于php 帖子Поискпонесколькимкастомфлдамвыгребаетпостыопределенноготипаитаксономиисопределеннымикастомфилд的主要内容,如果未能解决你的问题,请参考以下文章

csharp Однакнопкаизнескольких,инужнокликнутьпопервойчтосуществуетапоостальнымнекликатьдажееслиониест

sh Длякаждойсделаннойправкибезкоммитапоказатьизмененныйучастоккодаиспросить,должнолиэтоизменениепопа

php ИзменениенадписииссылкинакнопкеКупить

Erlangе демо

比特币不能购买特斯拉了!今日比特币狂跌背后的原因……

php Проверкауникальностимассива