[英]How to use multiple post_type in WP_Query?
我創建了自定義字段,並使用WP_Query
來輸出它們。 我有一個“可見性部分”和“可信度部分”,ACF 插件中的每個設置都有自定義帖子類型。 我的可見性部分運行良好,但我需要弄清楚如何將我的可信帖子類型添加到數組參數中,以便我可以在該底部輸出我的帖子。 我不認為我可以添加另一個 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>
您可以在
WP_Query
參數中使用數組傳遞多個post_type
。
$args = array(
'post_type' => array( 'visibility_section', 'credibility_section')
);
$query = new WP_Query( $args );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.