Query wp per ottenere le pagine figlie della pagina corrente
Qualcuno può aiutarmi con la wp_query?
Sto creando un file template/loop per creare una pagina archivio delle pagine figlie della pagina corrente.
Questa query deve essere automatica poiché la sto utilizzando in diverse pagine.
Questa è la mia query qui sotto, ma restituisce solo i miei post invece delle pagine figlie.
<?php
$parent = new WP_Query(array(
'post_parent' => $post->ID,
'order' => 'ASC',
'orderby' => 'menu_order',
'posts_per_page' => -1,
'post_type' => 'page' // Aggiunto per ottenere solo le pagine
));
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(); ?>
Grazie in anticipo per qualsiasi aiuto.
Josh

Devi cambiare child_of
in post_parent
e inoltre aggiungere post_type => 'page'
:
WordPress codex Wp_query Parametri Post & Pagina
<?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(); ?>

Sono consapevole che questa sia una domanda molto vecchia, ma dato che ci sono capitato, potrebbe succedere anche ad altri.
WordPress offre una soluzione molto semplice per elencare le pagine, dove è possibile aggiungere anche alcuni argomenti.
Questo è tutto ciò che ti servirà per visualizzare le pagine figlie:
wp_list_pages(array(
'child_of' => $post->ID,
'title_li' => ''
))
Consulta la pagina di riferimento per wp_list_pages per tutte le opzioni che puoi applicare.

Per riscrivere questo codice come una funzione in functions.php, è necessario aggiungere 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();
}
