[wp-hackers] Modify get_pages() behavior trough filter
Filippo Toso
filippo.toso at creativepark.it
Sat Jul 21 13:51:37 GMT 2007
Hi,
I'm trying to modify the behavior of the get_pages() function from a plugin.
I would like to add a child_of parameter to get_pages() when it is invoked
without the child_of or include parameters.
At the beginning I have tough I can solve this issue using a filter like the
following:
function get_pages_filter($result, $r) {
if ((!isset($r['child_of']) || empty($r['child_of'])) &&
(!isset($r['include']) || empty($r['include']))) {
$r['child_of'] = 5; // this is just an example
return get_pages($r);
}
return $result;
}
I have used the same code for get_categories and get_bookmarks filters and
they worked like a charm, but the get_pages() function behaves differently.
After applying the get_pages filter, the $pages array is passed to the
get_page_children() function that "strips out" any page that hasn't the
right post_parent value.
The only solution I have been able to find is to add a new filter named
pre_get_pages at the beginning of the get_pages() function just before the
extract($r); command:
$r = apply_filters('pre_get_pages', $r);
In this way it's possible to manipulate the get_pages parameter before they
are used.
Following the same logic, it can be useful to add a post_get_pages filter at
the end of the get_pages() function (don't know if it has to be inserted
before or after the wp_cache_set() call):
$pages = apply_filters('post_get_pages', $pages, $r);
I will appreciate any any idea to avoid the modification of the get_pages()
code.
Sincerely,
Filippo Toso
More information about the wp-hackers
mailing list