dongyong1942
2016-10-02 17:30
浏览 164
已采纳

如何在WP_Query中使用多个post_type?

I have created custom fields, and am using WP_Query to output them. I have a "visibility section" and "credibility section", with custom post types for each set up in the ACF plugin. My visibility section is working perfectly, but I need to figure out how to add my credibility post type to the array argument, so that I can output my posts in that bottom section. I don't think I can just add another post_type => 'credibility_section' to it...

<?php
  $args = array(
    'post_type' => 'visibility_section'
    //Can I add 'post_type' => 'credibility_section' here?
  );

  $query = new WP_Query( $args );
?>

<section class="row visibility-content"><!-- Start visibility section -->
  <div class="container">
    <h3 class="text-xs-center m-b-3">Visibility</h3>
    <div class="col-md-6">
    <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
      <p><?php the_field( 'visibility_left_column' ); ?></p>
    </div>
    <div class="col-md-6">
        <?php if( get_field( 'visibility_image' ) ): ?>
            <img src="<?php the_field( 'visibility_image'); ?>" />
        <?php endif; ?>
    </div>
    <div class="col-md-12">
      <p><?php the_field( 'visibility_bottom' ); ?></p>
    </div>
  <?php endwhile; endif; wp_reset_postdata(); ?>
  </div>
</section>

<section class="row cred-content"><!-- Start Credibility section -->
  <div class="container">
    <h3 class="text-xs-center m-b-3">Credibility</h3>
    <div class="col-md-12">

    </div>
</section>

图片转代码服务由CSDN问答提供 功能建议

我创建了自定义字段,并使用 WP_Query 输出它们。 我有一个“可见性部分”和“可信度部分”,每个设置在ACF插件中的自定义帖子类型。 我的可见性部分工作正常,但我需要弄清楚如何将我的可信度类型添加到数组参数,以便我可以在底部输出我的帖子。 我不认为我可以添加另一个post_type =&gt; 'reputation_section'到它......

 &lt;?php 
 $ args = array(
'post_type'=&gt;'visibility_section'
 // //我可以 在这里添加'post_type'=&gt;'distinguished_section'?
); 
 
 $ query = new WP_Query($ args); 
?&gt; 
 
&lt; section class =“row visibility-content”&gt  ;&lt;! - 开始可见性部分 - &gt; 
&lt; div class =“container”&gt; 
&lt; h3 class =“text-xs-center mb-3”&gt;可见性&lt; / h3&gt; \  n&lt; div class =“col-md-6”&gt; 
&lt;?php if($ query-&gt; have_posts()):while($ query-&gt; have_posts()):$ query-&gt;  the_post();  ?&gt; 
&lt; p&gt;&lt;?php the_field('visibility_left_column');  ?&gt;&lt; / p&gt; 
&lt; / div&gt; 
&lt; div class =“col-md-6”&gt; 
&lt;?php if(get_field('visibility_image')):?&gt;  
&lt; img src =“&lt;?php the_field('visibility_image');?&gt;”  /&gt; 
&lt;?php endif;  ?&gt; 
&lt; / div&gt; 
&lt; div class =“col-md-12”&gt; 
&lt; p&gt;&lt;?php the_field('visibility_bottom');  ?&gt;&lt; / p&gt; 
&lt; / div&gt; 
&lt;?php endwhile; 万一;  wp_reset_postdata();  ?&gt; 
&lt; / div&gt; 
&lt; / section&gt; 
 
&lt; section class =“row cred-content”&gt;&lt;! - 开始可信度部分 - &gt; 
&lt; div class  =“container”&gt; 
&lt; h3 class =“text-xs-center mb-3”&gt;可信度&lt; / h3&gt; 
&lt; div class =“col-md-12”&gt; 
 
  &lt; / div&gt; 
&lt; / section&gt; 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题