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>
  • 写回答

1条回答 默认 最新

  • duanjiu4498 2016-10-02 17:44
    关注

    You can pass multiple post_type using array in WP_Query argument.

    $args = array(
        'post_type' => array( 'visibility_section', 'credibility_section')
    );
    $query = new WP_Query( $args );
    


    Reference:
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!