包括两个类似的wp_query';s在一个模板中


Including two similar wp_query's in one template

我在Wordpress中设置了这个查询,以查找一家公司的所有相关新闻:

                        <h2 class="heading">Related News</h2>   
                        <?php $link = get_the_title(); ?>
                        <?php $portfolioloop = new WP_Query( array( 'post_type' => 'news' ) ); ?>
                    <?php while ( $portfolioloop->have_posts() ) : $portfolioloop->the_post(); ?>  
                        <?php $post_link = get_post_permalink(); ?>
                        <?php $post_title = get_the_title(); ?>                        
                        <?php  if (get_field('featured_companies') != "") { ?>
                            <p style="margin:0px!IMPORTANT;">
                            <?php foreach(get_field('featured_companies') as $post): ?>
                                <?php $company = get_the_title(); ?>
                                <?php if ($company == $link) { ?>
                                    <a href="<?php echo $post_link; ?>"><?php echo $post_title; ?></a><br />
                                <?php } ?> 
                            <?php endforeach;?>
                            </p>
                        <?php } ?>
                    <?php endwhile; wp_reset_query(); ?>

然后我想创建同样的东西,但找到所有与公司相关的事件。尽管新闻和事件的设置方式完全相同,但它似乎不起作用,我缺少什么???

                        <h2 class="heading">Related Events</h2>
                        <?php $link_e = get_the_title(); ?> 
                        <?php $portfolioloop_e = new WP_Query( array( 'post_type' => 'events' ) ); ?>
                    <?php while ( $portfolioloop_e->have_posts() ) : $portfolioloop_e->the_post(); ?>  
                        <?php $post_link_e = get_post_permalink(); ?>
                        <?php $post_title_e = get_the_title(); ?>                        
                        <?php  if (get_field('featured_companies') != "") { ?>
                            <p style="margin:0px!IMPORTANT;">
                            <?php foreach(get_field('featured_companies') as $post_e): ?>
                                <?php $company_e = get_the_title(); ?>
                                <?php if ($company_e == $link_e) { ?>
                                    <a href="<?php echo $post_link_e; ?>"><?php echo $post_title_e; ?></a><br />
                                <?php } ?> 
                            <?php endforeach;?>
                            </p>
                        <?php } ?>
                    <?php endwhile; wp_reset_query(); ?>

我试过wp_reset_query,但我不知道该怎么办!

只使用query_posts怎么样?我确信这会产生你想要的同样的结果?

<?php
  query_posts( array('post_type'=>'news') );
  if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
  <h3><?php the_title(); ?></h3>
  <?php the_content(); ?>
<?php 
endwhile; endif; wp_reset_query(); 
?>
<?php
  query_posts( array('post_type'=>'events') );
  if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
  <h3><?php the_title(); ?></h3>
  <?php the_content(); ?>
<?php endwhile; endif; wp_reset_query(); ?>

希望能有所帮助。。

马蒂。