我有自定义帖子类型设置 - 称为项目和启用的子页面。当我在父页面上时,我想查询父页面上子页面的内容。
这是我的尝试。这将查询称为项目的所有自定义帖子类型任何人都可以帮我查询子页面吗?
<?php
$args = array(
'child_of' => $post->ID,
'post_type' => 'projects',
'order' => 'ASC',
'orderby' => 'menu_order'
);
$wpq = new WP_Query( $args );
if( $wpq->have_posts() ): while( $wpq->have_posts() ): $wpq->the_post(); ?>
<div id="parent-<?php the_ID(); ?>" class="parent-page">
<?php echo the_content();?>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_query(); ?>
答案 0 :(得分:7)
我明白了。希望有其他人有这个问题会发现这个!我找到了get_pages的wordpress codex:http://codex.wordpress.org/Function_Reference/get_pages
<?php $children = get_pages(
array(
'sort_column' => 'menu_order',
'sort_order' => 'ASC',
'hierarchical' => 0,
'parent' => $post->ID,
'post_type' => 'projects',
));
foreach( $children as $post ) {
setup_postdata( $post ); ?>
<div class="section-container">
<?php the_content(); ?>
</div>
<?php } ?>
答案 1 :(得分:0)
<?php
$query = array('post_parent' => $post->ID, 'post_type' => 'page', 'posts_per_page' => '3','orderby' => 'date','order' => 'DESC');
$loop = new WP_Query($query);
if ($loop->have_posts()) : while ($loop->have_posts()) : $loop->the_post();
?>
<div class="section-container">
<?php echo wp_trim_words( get_the_content(), 40, '...' ); ?>
</div>
<?php endwhile; endif; ?>