I'm using the following code to get a list of all the pages that are children of my project page and display them in a Recent Projects section of my template's footer element.
I've noticed that the
get_page_children() method returns everything about that page -
post_title, etc. Is there a way to limit this so that it only returns the
post_title? Otherwise it is creating unnecessary overhead in querying all these other properties that aren't being rendered in the footer.
Also, is there a way to limit the number of objects returned? I only want the most recent four ordered by date descending.
<h3>Recent Projects</h3> <ul class="footer-list"> <?php // Set up the objects needed $my_wp_query = new WP_Query(); $all_wp_pages = $my_wp_query->query(array('post_type' => 'page')); // Get the page as an Object $projects = get_page_by_title('Projects'); // Filter through all pages and find Portfolio's children $projects_children = get_page_children( $projects->ID, $all_wp_pages ); // echo what we get back from WP to the browser foreach ($projects_children as $project): ?> <li> <a href="<?php echo get_permalink($project); ?>"><?php echo var_dump($project);//echo $project->post_title; ?></a> </li> <?php endforeach; ?> </ul>