get_pages( )函数用于获取博客中已定义页面的列表。下面是它的典型用法。


This function returns an array of pages that are in the blog, optionally constrained by parameters. This array is not tree-like (hierarchical). See the wp_list_pages() template tag for the output of page titles in a tree-like fashion.

This function can also retrieve other post types using the 'post_type' parameter, but the type must be hierarchical like pages, or the function will return false.

Note that, although similar to get_posts(), several of the parameter names and values differ. (It is implemented quite differently, see get_posts().)

NOTE: This function will currently not retrieve pages using the 'meta_key' and 'meta_value' parameters in the $args array as described below. Until this is fixed in the WordPress codebase, you may want to use get_posts() instead.

get_pages() 描述


 <?php get_pages$args ); ?> 

Default Usage

get_pages() 用法



(string) Sorts the list of Pages in a number of different ways. The default setting is sort alphabetically by Page title.

  • 'post_title' - Sort Pages alphabetically (by title) - default
  • 'menu_order' - Sort Pages by Page Order. N.B. Note the difference between Page Order and Page ID. The Page ID is a unique number assigned by WordPress to every post or page. The Page Order can be set by the user in the Write>Pages administrative panel.
  • 'post_date' - Sort by creation time.
  • 'post_modified' - Sort by time last modified.
  • 'ID' - Sort by numeric Page ID.
  • 'post_author' - Sort by the Page author's numeric ID.
  • 'post_name' - Sort alphabetically by Post slug. Not supported yet, as of WP 3.3 (See: )

Note: The sort_column parameter can be used to sort the list of Pages by the descriptor of any field in the wp_post table of the WordPress database. Some useful examples are listed here.

Note: get_posts() uses the parameter 'orderby' instead of 'sort_column'. Also, get_posts() automatically prepends 'post_' to these values: 'author, date, modified, parent, title, excerpt, content'.


(string) Change the sort order of the list of Pages (either ascending or descending). The default is ascending. Valid values:

  • 'asc' - Sort from lowest to highest (Default).
  • 'desc' - Sort from highest to lowest.

Note: get_posts() uses the parameter 'order' instead of 'sort_order'.


(string or array) Define a comma-separated list of Page IDs to be excluded from the list (example: 'exclude=3,7,31'). Beginning with Version 3.0, an array of Page ID also can be used. There is no default value.


(string or array) Only include certain Pages in the list generated by get_pages. Like exclude, this parameter takes a comma-separated list of Page IDs. Beginning with Version 3.0, an array of Page ID also can be used. There is no default value.

Note: If this parameter is provided, child_of, parent, exclude, meta_key, and meta_value params are ignored, and hierarchical is set to false.


(integer) Lists the sub-pages of a single Page only; uses the ID for a Page as the value. Defaults to 0 (list all Pages). Note that the child_of parameter will also fetch "grandchildren" of the given ID, not just direct descendants.

  • 0 - default, no child_of restriction

Note: The child_of parameter is not applied to the SQL query for pages. It is applied to the results of the query. If a number parameter is also provided, the final results may be less than the number specified.


(integer) List those pages that have the provided single page only ID as parent. Defaults to -1 (displays all Pages regardless of parent). Note that the 'hierarchical' parameter must be set to 0 (false) -- which is not default -- or else no results will be returned for any page other than the top level pages with no parent (ID=0) and the default all pages (ID=-1). In contrast to the 'child_of' parameter, this parameter only returns the direct descendants of the parent, no 'grandchildren'. You can obviate the 'hierarchical' set to 0 requirement by passing a 'child_of' parameter set to the same (parent) ID value.

  • -1 - default, no parent restriction
  • 0 - returns all top level pages


(integer) The opposite of 'child_of', 'exclude_tree' will remove all children of a given ID from the results. Useful for hiding all children of a given page. Can also be used to hide grandchildren in conjunction with a 'child_of' value. This parameter was available at Version 2.7.


(boolean) Lists sub-Pages below their parent or lists the Pages inline. The default is true (list sub-Pages below the parent list item). NOTE: This default value will prevent meta_key & parent page searches from finding sub-pages. You need to set 'hierarchical' => 0 for these parameters to work properly. Valid values:

  • 1 (true) - default
  • 0 (false)


(string) Only include the Pages that have this Custom Field Key (use in conjunction with the meta_value field).


(string) Only include the Pages that have this Custom Field Value (use in conjunction with the meta_key field).


(string) Only include the Pages written by the given author(s)

Note: get_posts() uses the parameter 'author' instead of 'authors'.


(integer) Sets the number of Pages to list. This causes the SQL LIMIT value to be defined. Default to no LIMIT. This parameter was added with Version 2.8.

Note: get_posts() uses the parameter 'numberposts' instead of 'number'.

Second Note: it doesn't work if used together with 'child_of'. Instead use 'parent' and set 'hierarchical' to false.


(integer) The number of Pages to pass over (or displace) before collecting the set of Pages. Default is no OFFSET. This parameter was added with Version 2.8.


("string") Show posts associated with certain type. Valid values include:

  • 'post' - a post.
  • 'page' - a page.
  • 'revision' - a revision.
  • 'attachment' - an attachment.
  • Custom Post Types.


(string) A comma-separated list of post status types that should be included. For example, 'publish,private,draft'.

get_pages() 参数


get_pages() 函数的代码位于 wp-includes/post.php.

get_pages() 源文件