I am looking to find a way to create a list of the IDs of children pages from a selected page.
My goal is to use the list of IDs so that I can exclude them from the following function:
wp_list_pages(array('exclude' => $###Children_Pages_to_be_excluded###, 'title_li' => ''));
I have checked the following question, but I am not sure how to use this function to achieve what I am trying to do.| Trying to list out child pages with WP_Query
I would appreciate any pointers. Many thanks for your assistance and time.
P.S.
I have managed to solve the problem with the following:
//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' => ''));
I am looking to find a way to create a list of the IDs of children pages from a selected page.
My goal is to use the list of IDs so that I can exclude them from the following function:
wp_list_pages(array('exclude' => $###Children_Pages_to_be_excluded###, 'title_li' => ''));
I have checked the following question, but I am not sure how to use this function to achieve what I am trying to do.| Trying to list out child pages with WP_Query
I would appreciate any pointers. Many thanks for your assistance and time.
P.S.
I have managed to solve the problem with the following:
//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' => ''));
Share
Improve this question
edited Jan 7, 2019 at 15:43
Peter
asked Jan 7, 2019 at 14:05
PeterPeter
12 bronze badges
8
|
Show 3 more comments
1 Answer
Reset to default 0//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' => ''));
wp_list_pages
or the exclude but still gives you the same result – Tom J Nowell ♦ Commented Jan 7, 2019 at 14:19