Вывести родительские страницы wordpress
всем привет. Нужно вывести дочерние страницы из 3-х родительских. Выглядит это так: заголовки 3-х родительских страниц и под ними все ихние дочерние страницы.
Есть такой код: выводится не так как надо.
<?php global $post;
$args_parent = array(
'post_type' => 'page',
'include' => array(20,37,23),
'posts_per_page' => 3
);
$query = get_posts( $args_parent );
foreach($query as $product) { ?>
<div class="production-item">
<?php
$children = array(
'post_type' => 'page',
'child_of' => $product->ID,
);
$child = new WP_Query( $children ); ?>
<div class="production-item-title"><?php echo $product->post_title; ?></div>
<ul class="production-item-list">
<?php if ( $child->have_posts() ) {
while ( $child->have_posts() ) {
$child->the_post(); ?>
<li><?php the_title(); ?></li>
<?php } } wp_reset_postdata(); ?>
</ul>
</div>
<?php }
?>
Ответы (1 шт):
Автор решения: alenkins
→ Ссылка
Вместо параметра child_of используйте post_parent__in
Другими словами:
<?php
$children = array(
'post_type' => 'page',
'post_parent__in' => array($product->ID),
);
?>
Подробнее про параметры запроса читайте в справке.
