WP codex中的示例get_page_children
通过标题为“Portfolio”的页面实现您想要的功能:
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array(\'post_type\' => \'page\', \'posts_per_page\' => \'-1\'));
// Get the page as an Object
$portfolio = get_page_by_title(\'Portfolio\');
// Filter through all pages and find Portfolio\'s children
$portfolio_children = get_page_children( $portfolio->ID, $all_wp_pages );
第一部分初始化一个新的WP\\u查询,然后使用它查询所有页面并将其作为设置为
$all_wp_pages
变量
get_page_children
需要两个参数:父页的ID和要在其中查找该页的子页的页对象列表($all_wp_pages
变量)。
为了使示例起作用,您需要查询创建的对象列表($all_wp_pages
) 作为get_page_children
doesn\'t query the DB, but rather checks against that list.
所以get_page_children($post->ID, $all_wp_pages)
全文:
$page_id = $post->ID;
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array(\'post_type\' => \'page\', \'posts_per_page\' => \'-1\'));
$the_pages_children = get_page_children( $page_id, $all_wp_pages );