wp consulta para obtener páginas secundarias de la página actual

23

¿Puede alguien ayudarme con la wp_query?

Estoy creando un archivo / bucle de plantilla para crear y archivar la página de las páginas secundarias de la página actual.

Esta consulta debe ser automática, ya que la uso en algunas páginas.

Esta es mi consulta a continuación, pero solo devuelve mis publicaciones en lugar de páginas secundarias.

<?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

    
pregunta Joshc 31.07.2012 - 11:14

1 respuesta

58

Tienes que cambiar child_of a post_parent y también agregar post_type => 'page' :

WordPress codex Wp_query Publicar y amp; Parámetros de 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(); ?>
    
respondido por el Pontus Abrahamsson 31.07.2012 - 11:23

Lea otras preguntas en las etiquetas