WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] in the list of child_pages is always an autosave Link of the parent (3 posts)

  1. Monika
    Member
    Posted 5 years ago #

    I would like to show a list of child_pages on a parent page.

    now WP shows me always a link to an autosave post from the parent page, the link is linking to error 404 and I don't know how to stop this.

    Parent Pages name is *Hi
    the child_pages

    good
    fun

    I edit the page *Hi and now the list show me

    *Hi with an false url
    good
    fun

    my code to display the child pages is:

    if ( is_page() ) :
    global $post, $wpdb;
    $parent_ID = ($post->post_parent) ? $post->post_parent : $post->ID;
    $pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = $parent_ID");
    if($pages) : foreach($pages as $post) : // child pages loop
    setup_postdata($post);
    ......my stuff
    endforeach; endif; // end child pages loop
    endif;
  2. MichaelH
    Member
    Posted 5 years ago #

    If you only want a list of child pages, not the content, then consider:
    http://wordpress.org/support/topic/240367

  3. Monika
    Member
    Posted 5 years ago #

    HI thanks MichaelH

    I have forgotten the post_status -now it works :-)

    post_parent = $parent_ID AND post_status = 'publish'

    if ( is_page() ) : // is_page test
    global $post, $wpdb;
    $parent_ID = ($post->post_parent) ? $post->post_parent : $post->ID;
    $pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = $parent_ID AND post_status = 'publish' ");
    if($pages) : foreach($pages as $post) : // child pages loop
    setup_postdata($post);?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark" title=" <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
    <?php
    endforeach; endif; // end child pages loop
    endif;

    thanks for your answer

Topic Closed

This topic has been closed to new replies.

About this Topic