wp query para obtener páginas hijas de la página actual
¿Alguien puede ayudarme con wp_query?
Estoy creando un archivo de plantilla/bucle para crear una página de archivo de las páginas hijas de la página actual.
Esta consulta necesita ser automática ya que la estoy usando en varias páginas.
Esta es mi consulta a continuación, pero solo devuelve mis entradas en lugar de las páginas hijas.
<?php
$parent = new WP_Query(array(
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order',
'posts_per_page' => -1
));
if ($parent->have_posts()) : ?>
<?php while ($parent->have_posts()) : $parent->the_post(); ?>
<div id="parent-<?php the_ID(); ?>" class="parent-page">
<h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
<p><?php the_advanced_excerpt(); ?></p>
</div>
<?php endwhile; ?>
<?php unset($parent); endif; wp_reset_postdata(); ?>
Gracias de antemano por cualquier ayuda.
Josh

Debes cambiar child_of
por post_parent
y también añadir post_type => 'page'
:
Código de WordPress Wp_query Parámetros de Post & Página
<?php
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) : ?>
<?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
<div id="parent-<?php the_ID(); ?>" class="parent-page">
<h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
<p><?php the_advanced_excerpt(); ?></p>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>

Gracias amigo, probé con post_parent
originalmente pero es 'post_type' => 'page'
lo que era la clave - ¿las consultas de WordPress usan post por defecto entonces? Aceptaré la respuesta cuando me deje hacerlo.

Sé que esta es una pregunta muy antigua, pero como llegué aquí, otros también podrían hacerlo.
WordPress tiene una solución muy simple para listar páginas, donde también puedes agregar algunos argumentos.
Esto es todo lo que necesitarás para mostrar las páginas hijas de una página:
wp_list_pages(array(
'child_of' => $post->ID,
'title_li' => ''
))
Mira la página de referencia para wp_list_pages para ver todas las opciones que puedes aplicar.

Para reescribir esto como una función en functions.php necesitas agregar global $post;
function page_summary() {
global $post;
$args = array(
'post_type' => 'page',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order'
);
$parent = new WP_Query( $args );
if ( $parent->have_posts() ) :
while ( $parent->have_posts() ) : $parent->the_post(); ?>
<div id="parent-<?php the_ID(); ?>" class="parent-page">
<h1><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
</div>
<?php
endwhile;
endif;
wp_reset_postdata();
}
