创建不包括所选页面的子级的页面列表

时间:2019-01-07 作者:Peter

我正在寻找一种方法,从所选页面创建子页面ID列表。

我的目标是使用ID列表,以便从以下函数中排除它们:

wp_list_pages(array(\'exclude\' => $###Children_Pages_to_be_excluded###, \'title_li\' => \'\'));
我已经检查了以下问题,但我不确定如何使用此函数来实现我正在尝试的操作|Trying to list out child pages with WP_Query

如果有任何建议,我将不胜感激。非常感谢您的帮助和时间。

P、 S。

我已成功解决以下问题:

//Create an array containing the IDs of pages that are children of page ID XXX"
$args = array(
\'post_type\' => \'page\',
\'post_parent\' => XXX,
\'fields\' => \'ids\',
\'posts_per_page\' => -1,
);
$qry = new WP_Query($args);

//Convert the array into a string
$string = implode(\', \', $qry->posts);

//Create a list of all pages
wp_list_pages(array(\'exclude\' => $string, \'title_li\' => \'\'));

1 个回复
SO网友:Peter
//Create an array containing the IDs of pages that are children of page ID XXX
$args = array(
\'post_type\' => \'page\',
\'post_parent\' => XXX,
\'fields\' => \'ids\',
\'posts_per_page\' => -1,
);
$qry = new WP_Query($args);

//Convert the array into a string
$string = implode(\', \', $qry->posts);

//Display the list of IDs - for testing purposes.
//var_dump($string);                

//Create a list of all pages excluding the list of child pages
wp_list_pages(array(\'exclude\' => \'XXX,\'.$string, \'title_li\' => \'\'));