即使帖子类型存在,WordPress第二个自定义WP_Query也不会显示?

时间:2019-06-20 11:26:16

标签: php wordpress wordpress-theming advanced-custom-fields

我这里有个奇怪的问题。我的第二个自定义帖子类型“扬声器”没有显示。不久之后,我尝试使用“ wp_reset_postdata()”,但仍然无法显示HTML块。

之后:<?php if($query->have_posts()): ?>没有任何显示。

我的文件:

<?php
/*
 * Template Name: Speakers overview
 */
get_header();
?>

<?php if(have_posts()): ?>
    <?php
    while(have_posts()) : the_post();
    $subtitel = get_field('subtitel');
    $GLOBALS['footerbanner'] = get_field('footerbanner');
    ?>

    <div class="row">
        <div class="col l12-10 m3-2 s3-3 pre_l12-2">
            <h2 class="has_animation" data-aos="fade-down" data-aos-delay="100">
                <?php the_title(); ?>
            </h2>

            <?php if(!empty($subtitel)): ?>

            <h5>
                <?php echo $subtitel; ?>
            </h5>

            <?php
                echo "\n";
                endif;
            ?>
        </div>

        <?php if ( has_post_thumbnail()): ?>
            <div class="col l3-3 m3-3 s3-3">
            <?php the_post_thumbnail('detail'); ?>
            </div>
        <?php endif; ?>

        <div class="col l12-8 m3-3 s3-3 pre_l12-2 intro"  data-aos="fade-right" data-aos-delay="400">
            <?php the_content(); ?>
        </div>

        <div class="clearfix"></div>
    </div>

    <div class="section" id="speakers">
        <div class="row">
        <?php
            $year   = date('Y');
            $args_s = array(
            'post_type'      => 'speaker',
            'posts_per_page' => -1,
            'meta_key'       => 'speaker_date',
            'orderby'        => 'menu_order',
            'order'          => 'ASC',
            'meta_query'     => array(
                array(
                'key'       => 'speaker_date',
                'value'     => $year,
                'compare'   => '>',
                'type'      => 'DATE',
                )
            )
        );

        $query_s = new WP_Query($args_s);
        $s = 0;

        if ($query_s->have_posts()):
            while ($query_s->have_posts()) :  $query_s->the_post();
            $company        = get_field('company');
            $claim_color    = get_field('post_it_color');
            $claim          = get_field('claim');
                if ($s % 2 == 0):
                $even_class     = ' pre_l12-1 suf_l4-2';
                $poster_pos     = ' is_extra_right';
                $animate        = 'fade-left';
                else:
                $even_class = ' pre_l12-5 pre_m4-1';
                $animate = 'fade-right';
                $poster_pos = '';
                endif;

            ?>

            <div class="col l4-2 m4-3 s3-3<?php echo $even_class; ?>" data-aos="<?php echo $animate; ?>" data-aos-duration="800">
                <a class="block_link" href="<?php the_permalink(); ?>">
                    <?php the_post_thumbnail('medium_crop' ); echo "\n"; ?>
                            <h3><?php the_title(); ?></h3>
                        <?php if(!empty($company)): ?>
                            <h5><?php echo $company; ?></h5>
                        <?php echo "\n"; endif; ?>
                        <span class="readmore">Read more <span class="icon icon_arrow"></span></span>
                </a>

                <?php if(!empty($claim)): ?>
                <div class="posterwrap rellax<?php echo $poster_pos; ?>" data-rellax-speed="<?php echo ( mt_rand(0,100) ) / 100; ?>">
                    <div class="poster <?php echo $claim_color; ?>  rotate_<?php echo mt_rand(-10,10); ?>">
                        <div class="poster--claim">
                            <?php echo $claim;?>
                        </div>
                    </div>
                </div>
                <?php endif; ?>
            </div>

            <?php
            $s++;
            endwhile;
            wp_reset_postdata();
        endif;
        ?>
            <div class="clearfix"></div>
        </div>
    </div>

    <?php
    endwhile;
    wp_reset_postdata();
    ?>
<?php endif; ?>

<?php
    $year = date('Y');
    $args = array(
    'post_type'      => 'speaker',
    'posts_per_page' => -1,
    'meta_key'       => 'speaker_date',
    'orderby'        => 'meta_value',
    'order'          => 'ASC',
    'meta_query'    => array(
            array(
            'key'       => 'speaker_date',
            'value'     => $year,
            'compare'   => '<',
            'type'      => 'DATE',
            )
        )
    );
    $query = new WP_Query($args);
    $found = $query->found_posts;
?>

<?php if($query->have_posts()): ?>
    <div class="row is_related">
        <div class="col l12-10 m3-3 s3-3">
            <h3 class="is_xxl">Previous Speakers</h3>
        </div>

        <div class="clearfix"></div>

        <div class="sliderwrap all_speakers">
            <div class="slider">
                <?php
                    while($query->have_posts()) : $query->the_post();
                        get_template_part('blocks/block', 'speaker');
                    endwhile;
                    wp_reset_postdata();
                ?>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
<?php endif; ?>

<?php get_footer(); ?>

0 个答案:

没有答案