$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>exclude - Create a list of pages excluding children of selected page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

exclude - Create a list of pages excluding children of selected page

matteradmin9PV0评论

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
  • Keep in mind that any kind of "exclude" or "not_in" type queries can be surprisingly expensive/slow, and don't scale very far. Why are you trying to exclude them? If you provide more context there may be an alternative that doesn't involve wp_list_pages or the exclude but still gives you the same result – Tom J Nowell Commented Jan 7, 2019 at 14:19
  • Thanks for your reply! Here is what I am trying to do in more detail. I am creating a dynamic HTML sitemap page containing all the pages from my website. For this purpose I am using the following function: wp_list_pages(array('exclude' => '', 'title_li' => '')); This query works fine and it produces exactly the result I am looking for with one exception. – Peter Commented Jan 7, 2019 at 14:27
  • What I am trying to do next is to exclude a list of pages, that are all children of a selected page X. Here is where I'm at currently: $args = array( 'child_of' => ###ID_of_parent_page_X 'post_type' => 'page', 'post_status' => 'publish' ); $excluded_pages = get_pages($args); The final query produces an array of the CONTENT of pages. However, I need an Array of the page IDs, not their content. Finally, I am trying to use the $excluded_pages variable as an exclude term inside the first function (above). Hope this explanation is sufficient. Thank you in advance! – Peter Commented Jan 7, 2019 at 14:28
  • P.S. I have managed to create a list of IDs of the child pages using the following query: $args = array( 'post_type' => 'page', 'post_parent' => 11702, 'fields' => 'ids', 'posts_per_page' => -1, ); $qry = new WP_Query($args); var_dump($qry->posts); I am trying to use it as exclude term here: wp_list_pages(array('exclude' => '$qry->posts', 'title_li' => '')); Apparently, I am missing something, as the pages that need to be excluded are still present in the sitemap. – Peter Commented Jan 7, 2019 at 15:03
  • Can you edit your question to include that code inside code blocks? It's unreadable in comments and difficult to follow – Tom J Nowell Commented Jan 7, 2019 at 15:32
 |  Show 3 more comments

1 Answer 1

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' => ''));
Post a comment

comment list (0)

  1. No comments so far