RPeraltaJr
5/25/2017 - 9:05 PM

List All Child Pages (Will only display 'published' pages)

List All Child Pages (Will only display 'published' pages)

<?php

  // Array of all Location child pages
  $locations_array = array(
    'post_type' => 'page',
    'orderby' => 'title',
    'order'	=> 'DESC',
    'post_parent'	=> 265, // Parent Page Id
    'posts_per_page' => -1 // default is Limit 5, -1 means No Limit
  );
  
  // Use 'get_posts' function
  $location_pages = get_posts($locations_array);

  // Use data in loops
  foreach ($location_pages as $location_page) { 
    // Get ACF value of child page
    $image = get_field( 'main_img', $location_page->ID );
    // Splitting the Page Title for (City, Country) format
		$title_array = explode(",", $location_page->post_title);
		$city = $title_array[0];
		$country = $title_array[1];
?>
  
    <li>
      <a href="<?php echo get_permalink($location_page->ID); ?>">
        <p><?php echo $location_page->post_title; ?></p>
      </a>
    </li>
    
<?php } ?>