WordPress获取页面ID、名称列表函数:get_page_hierarchy

WordPress函数get_page_hierarchy以页面ID为键,名称为值返回页面列表数组。

get_page_hierarchy( WP_Post[] $pages, int $page_id )

函数参数

$pages

数组

页面列表对象,用get_pages()函数获取

$page_id

整数,默认值:0

父页面ID,仅返回指定ID页面的子页面。

函数返回值

Array
(
    [2] => about
    [10] => job
    [15] => contact
    [13] => links
    [8] => service
)

函数使用示例

$all_pages = get_pages( array(
	'post_type'         => 'page',
	'post_status'       => array( 'publish' )
) );
$page_list = get_page_hierarchy($all_pages);

扩展阅读

get_page_hierarchy()函数位于:wp-includes/post.php

相关函数:

阿里云