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

时间:2018-01-22 16:47:43

标签: php wordpress 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(); ?>

1 个答案:

答案 0 :(得分:0)

您需要在args中添加post_parent变量。虽然只有那段代码,但我无法看到你需要做什么来引用post_id。

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