The WordPress get_pages function works similar to the get_posts function which fetches posts from the database by criteria. The get_pages function takes different arguments and allows you to take control of parent and child pages as you execute the function.

Usage :

<?php $pages = get_pages($arguments); ?>

Example :

<?php

$arguments = array(
	'child_of'		=>	0,
	'sort_order'	=>	"DESC",
	'sort_column'	=>	"post_title",
	'exclude'		=>	"3,7,8",
);

$pages = get_pages($arguments);

?>

Parameters :

  • $child_of
    The ID of the parent page. Allows you to fetch child pages of a specific parent page. Use 0 or null or false in order to fetch all parent and child pages.
  • $sort_order
    The direction in which the results should be sorted. This can be either ASC or DESC. Works in conjunction with the $sort_column parameter explained below.
  • $sort_column
    The database column to order by. Makes use of the $sort_order parameter explained above.
  • $exclude
    Comma delimited list of page IDs to exclude from the results
  • $include
    Comma delimited list of page IDs to include into the results
  • $authors
    Comma delimited list of the authors to which the pages belong. Only pages created by these authors will be included into the results
  • $meta_key
    Matches a specific meta key and only includes those pages into the results
  • $meta_value
    Matches a specific meta value and only includes those pages into the results
  • $hierarchical
    If set to 1, pages will be fetched in a hierarchical manner