简体   繁体   English

如何仅显示自定义帖子类型的子帖子?

[英]How to display only the child posts of a custom post type?

Im having trouble trying to find a solution to display the child posts in a custom post type on the custom post type's archive page. 我在寻找解决方案以在自定义帖子类型的存档页面上以自定义帖子类型显示子帖子时遇到麻烦。

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

You need to add the post_parent variable in your args. 您需要在参数中添加post_parent变量。 Though with only that code I can't see what you'd need to do to reference the post_id. 虽然只有该代码,但我看不到要引用post_id所需执行的操作。

$args = array(
    'post_parent' =>  $post->ID,
    'posts_per_page' => -1,
    'post_type' => 'locations'
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM