WordPress的第二循环总是空的

时间:2019-03-28 22:23:33

标签: wordpress

我尝试在一页上添加两个WP_Query,但是由于某种原因,第二个Query从不显示数据。实际上$ the_query2-> has_posts()是错误的。我认为我无法正确重置循环是有问题的,因为当我更改两个查询的顺序时,$ the_query2有效但$ the_query1无法工作。因此,始终只有第一个起作用。有想法吗?

            <h3>Coworking communities</h3>
        <?php
             $args = array( 'post_type' => array('organizations'), 'type' => 'coworking-communities', 'stage' => get_the_title(), 'orderby' => 'rand', 'order' => 'desc');
            $the_query1 = new WP_Query( $args );

            while ( $the_query1->have_posts() ) : $the_query1->the_post();

                get_template_part( 'template-parts/content', 'organization' );

            endwhile; // End of the loop.
            wp_reset_postdata();
            wp_reset_query();

?>

        <h3>Mentoring & Events</h3>
        <?php
            $args = array( 'post_type' => array('organizations'), 'type' => 'mentoring-and-events', 'stage' => get_the_title(), 'orderby' => 'rand', 'order' => 'desc');
            $the_query2 = new WP_Query( $args );

            while ( $the_query2->have_posts() ) : $the_query2->the_post();

                get_template_part( 'template-parts/content', 'organization' );

            endwhile; // End of the loop.
            wp_reset_postdata();
            wp_reset_query();
?>

当我检查查询时,我意识到有一个0 = 1,这显然总是错误的。我怎样才能解决这个问题?如果我先运行此查询,为什么不存在?

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( 0 = 1 AND wp_term_relationships.term_taxonomy_id IN (31) ) AND wp_posts.post_type = 'organizations' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY RAND() LIMIT 0, 10

0 个答案:

没有答案