Allow get_pages to exclude by slug in addition to id
|Reported by:||richcon||Owned by:||garyc40|
Currently, get_pages() allows template authors to exclude certain pages from the result, by their ID. It's more useful to exclude by slug when the IDs aren't immediately known.
For example, on a WordPress site I recently made, I coded an automatically-generated menu listing the site's pages and their subpages. There are certain classes of pages I want to exclude, and hard-coding the page IDs into my menu code just isn't a good way to do it. Excluding by page slug works beautifully.
Patch: I've included a patch to add this functionality. It is a very short addition to wp-includes/post.php (one new line and two altered lines), has been well used on my (now live) site, and adds a very useful feature.
Syntax: The syntax is identical to the old use, except that where the "exclude" parameter only accepted numbers, it now can take strings. If the value given is not a number, it's treated as a slug. If it is a number, it's treated as an ID like before. For example:
$subPages = get_pages('hierarchical=0&exclude=sidebar&parent='.$page->ID);
will get subpages of $page that don't have the "sidebar" slug. (Numerical values are still treated as IDs, and lists can contain any number of IDs and slugs to exclude.)
Change History (19)
comment:8 wojtek.szkutnik — 3 years ago
- Cc wojtek.szkutnik@… added
- Keywords has-patch needs-testing gsoc added; needs-patch removed
- Owner changed from anonymous to garyc40
- Status changed from new to assigned