[英]How to display only the child posts of a custom post type?
我在尋找解決方案以在自定義帖子類型的存檔頁面上以自定義帖子類型顯示子帖子時遇到麻煩。
<?php wp_reset_postdata();
// WP_Query arguments
$args = array (
'post_type' => 'locations',
'posts_per_page' => -1,
);
// The Query
$location_query = new WP_Query( $args );
?>
<?php if ( $location_query->have_posts()): ?>
<ul>
<?php while ( $location_query->have_posts() ) : $location_query->the_post();
$location = get_field('map');
?>
<li>
<?php echo $location['address']; ?>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
您需要在參數中添加post_parent
變量。 雖然只有該代碼,但我看不到要引用post_id所需執行的操作。
$args = array(
'post_parent' => $post->ID,
'posts_per_page' => -1,
'post_type' => 'locations'
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.