如何在WP_Query中使用多个post_type?

How to use multiple post_type in WP_Query?

我已经创建了自定义字段,并且正在使用 WP_Query 来输出它们。我有一个 "visibility section" 和 "credibility section",在 ACF 插件中为每个设置自定义了 post 类型。我的可见性部分运行良好,但我需要弄清楚如何将可信度 post 类型添加到数组参数,以便我可以在该底部部分输出我的 posts。我不认为我可以再添加一个 post_type => 'credibility_section'...

<?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>

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 );


参考: