I would like to create 2 lists of pages and include and exclude some of them depending on their category. In the following example, I have my 2 lists. A list of promoted pages and a list for the rest.

    <ul class="promoted">
        <?php wp_list_pages('include=4');?>
        <?php wp_list_pages('exclude=4');?>

I have added my pages to the specific category (4) but no luck.

  • Please read Codex (or even better: The phpDocBlock in source) again: "Like exclude, this parameter takes a comma-separated list of Page IDs.". That's not the category ID there...
    – kaiser
    Oct 20, 2014 at 1:07
  • @kaiser, thanks but yes after testing I can see it won't work and am now asking for help on how to achieve this. The question remains.
    – Gab
    Oct 20, 2014 at 1:11
  • Gab, just try something, edit your question with what you know now and after some try and fail. The more you try, the better your question, the more effort you invest, the better the answer.
    – kaiser
    Oct 20, 2014 at 1:15
  • @kaiser I get it but i think it's quite clear. I have a category ID I would like to include or exclude from that list if possible. If not, I'll just explicitly use post IDs.
    – Gab
    Oct 20, 2014 at 1:30
  • Few remarks: Pages don't support categories by default, so it's not clear what taxonomy you mean here. How are you going to cut the tree in general? For example what if a leaf is in the include category but the rest of the branch isn't?
    – birgire
    Oct 28, 2014 at 9:43

2 Answers 2


One quick way of doing it without having to set up multiple loops would be to use the get_posts() function and grab all pages, then check through them with in_category() and split out pages that are in the category and pages that are not.

You can then run through the 2 groups of pages separately in your ULs with a simple foreach loop.

<?php $args = array(
    'post_type' =>  'page',
    'post_status'   =>  'publish',
    'numberposts'   =>  -1

//Pull pages into an array
$all_pages = get_posts($args);

//Create empty arrays to populate with filtered pages
$in_category = array();
$ex_category = array();

//loop through the page array
foreach($all_pages as $post) {
    //Set data from the current page as globals,
    //to enable WordPress function tags

    //Build the format of the link to be returned
    $link_format = '<li><a href="'.get_the_permalink().'">'.get_the_title().'</a></li>';        

    //Check whether the page is in the category and
    //send this link to the relevant array
    if(in_category(4)) {
        $in_category[] = $link_format;
    } else {
        $ex_category[] = $link_format;

//Restore postdata to before we set it to the current post
wp_reset_postdata(); ?>

<ul class="links_in_category_4">
    <?php foreach($in_category as $cat_link) echo $cat_link; ?>

<ul class="links_not_in_category_4">
    <?php foreach($ex_category as $cat_link) echo $cat_link; ?>
  • Thank you very much. This is exactly what I looking for!
    – Gab
    Oct 28, 2014 at 12:43

I actually have a large page based website that I am working on. Since it is mainly page driven, I used a function to allow categories and tags on pages. I would love to know if there is a way to exclude a category using the wp_list_pages() function. This would allow me to put in one id or slug rather than updating it with a new page id each time I have a new page that I want to exclude.

To be even more specific, I am using the following function which uses the wp_list_pages() function within it.

function wpb_list_child_pages() { 

global $post; 

if ( is_page() && $post->post_parent )

    $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
    $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );

if ( $childpages ) {

    $string = '<ul>' . $childpages . '</ul>';

return $string;


add_shortcode('wpb_childpages', 'wpb_list_child_pages');

That function can be found here: https://www.wpbeginner.com/wp-tutorials/how-to-display-a-list-of-child-pages-for-a-parent-page-in-wordpress/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.