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:
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用