Support » Plugins » Retrieve specific child page with query_posts($query)

  • Resolved elC0mmen


    Hello everybody!

    I am using WP as a CMS. I have a number pages (the names of student dorms), lets say ‘dorm1′, dorm2’, etc. and each of them has childres pages with THE SAME names/slugs, eg. ‘dorm1/tutoren’, ‘dorm1/sonstiges’, ‘dorm2/tutoren’, ‘dorm2/sonstiges’ , etc.

    I want that the dorm pages ‘dorm1’ show the ‘tutoren’ child page, so I tried this, but it doesn’t work.

    $post_id = get_post($post->ID);
    $slug = $post_id->post_name;
    $query = 'pagename='.$slug.'/tutoren';

    Where is the error?
    Also, I want this to happen only on “mother” pages, not the children. I tried this:

    if($post->post_parent) {
    //the above code

    Many thanks for you help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • There’s an example in Function_Reference/get_pages that you might find useful.

    Thanks A LOT! That helped! This is my solution!

    <?php //
    $pages = get_pages('child_of='.$post->ID);
    foreach($pages as $page)
    	$content = $page->post_content;
    		$content = apply_filters('the_content', $content);
    	else continue;
    <h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
    <div class="entry"><?php echo $content ?></div>
    <?php    }   ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Retrieve specific child page with query_posts($query)’ is closed to new replies.