[resolved] wp_list_pages() child_of not working (3 posts)

  1. tee05
    Posted 6 years ago #

    Hi, I was wondering if someone could help me get the following code working. Basically, I'm using the wp_list_pages() array code to get the parameters of 'child_of' ID. (I'm using this code because I'd like to list the pages without the use of list tags <li></li>). So far it's worked fine expect when I try to display the child pages of a parent page it doesn’t seem to pick up the ID correctly. Here's the code:

    $args = array(
    'post_type'   => 'page',
    'child_of'    => 2, // Problem Here
    'echo'        => 1,
    'sort_column' => 'menu_order',
    'depth'       => 0,
    $pages = get_posts($args);
      foreach($pages as $page) {
    	  $out .= '';
    	  $out .=  '<a href="'.get_permalink($page->ID).'" title="'.wptexturize($page->post_title).'">'.wptexturize($page->post_title).'</a>';
    $out = '' . $out . '';
    echo $out;
  2. MichaelH
    Posted 6 years ago #

    Consider using get_pages() instead of get_posts().

  3. tee05
    Posted 6 years ago #

    Thank you that helped! Incase anyone else needs this code:

    	$pages = get_pages('child_of=2&sort_column=post_date');
    	$count = 0;
    	foreach($pages as $page)
    		<a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a>

Topic Closed

This topic has been closed to new replies.

About this Topic