• Resolved Copernicus

    (@copernicus)


    Using wp_list_pages, it makes complete sense to exclude either specific pages via ID -or- the current page via 'exclude' => $post->ID,.

    However, I wish to exclude BOTH specific pages and the current page from the list.

    So, if I wanted to exclude pages with IDs ‘1,’ ‘2,’ and ‘3’ plus the current page, is there some way to combine the two excludes?
    I’ve tried things like
    'exclude' => '1,2,3,'.$post->ID., but nothing I’ve tried has yet to work.

    Any help is appreciated!

    (My searches through this forum & online in general have only resulted in one form of exclude or the other – not both.)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    From the doc page:

    ‘exclude’:
    (string) Comma-separated list of page IDs to exclude.

    and the example they show is <?php wp_list_pages( ‘exclude=17,38’ ); ?>

    https://developer.wordpress.org/reference/functions/wp_list_pages/

    Thread Starter Copernicus

    (@copernicus)

    Right, yes, that’s the same as what I referenced above.
    I completely understand how to exclude specific pages with something like <?php wp_list_pages( 'exclude=17,38' ); ?> and I understand how to exclude the current page with exclude=".$post->ID.".

    What I’m trying to do is exclude BOTH the specific list AND the current page.

    If it help clarifies the issue, this is what I currently have:

    wp_list_pages( array(
       'title_li'    => '',
       'child_of'    => '1',
       'show_date'   => 'modified',
       'exclude'    => '2,3,4,5',
       'depth'    => 1,
       'date_format' => $date_format
     ) );

    If I changed “'exclude' => '2,3,4,5',” to “'exclude' => $post->ID” then it would exclude the current page instead of that specific lists of page IDs. But, I want to do both.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    $excludes = "1,2,3,4,5," . $post->ID;
    wp_list_pages( 'exclude' => $excludes );
    Thread Starter Copernicus

    (@copernicus)

    YES! That did it. THANK YOU!

    For any others who may find this in the future, here’s the change that I made to the code above to work in the manner that I was seeking.

    If my original code was:

    wp_list_pages( array(
       'title_li'    => '',
       'child_of'    => '1',
       'show_date'   => 'modified',
       'exclude'    => '2,3,4,5',
       'depth'    => 1,
       'date_format' => $date_format
     ) );

    The modified code (from sterndata’s assistance), is:

    $excludes = "2,3,4,5," . $post->ID;
    wp_list_pages( array(
       'title_li'    => '',
       'child_of'    => '1',
       'show_date'   => 'modified',
       'exclude'    => $excludes,
       'depth'    => 1,
       'date_format' => $date_format
     ) );

    Thanks again, sterndata!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Excluding Current Page AND Specific Other Pages with wp_list_pages’ is closed to new replies.