[wp-trac] [WordPress Trac] #9383: Allow get_pages to exclude by
slug in addition to id
WordPress Trac
wp-trac at lists.automattic.com
Tue Mar 24 03:20:45 GMT 2009
#9383: Allow get_pages to exclude by slug in addition to id
-------------------------+--------------------------------------------------
Reporter: richcon | Owner: anonymous
Type: enhancement | Status: new
Priority: normal | Milestone: Unassigned
Component: General | Version: 2.7.1
Severity: normal | Keywords: has-patch
-------------------------+--------------------------------------------------
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.)
--
Ticket URL: <http://core.trac.wordpress.org/ticket/9383>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list