[英]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.