[wp-hackers] what is the best (fastest) way to check if a page has children?

André Schieleit wphackerslist at anschitech.de
Sun Mar 30 18:36:09 GMT 2008


I searched the internet, but found no simple/fast solution.
I want to check if a page has sub-pages to prevent some html being  
I have a homemade theme, where I used this line that worked well up  
to WP 2.3.3:

   if(get_page_children($myid, $pages)) :

$myid is populated with the ID of the current page. $pages is empty.

With WP 2.5 I encounter this error:
Warning: Invalid argument supplied for foreach() in /[server_path]/wp- 
includes/post.php on line 1783

So it seems to me, that there has something changed in 2.5 that  
causes the failure.
Is there any wordpress function that provides only the information  
that a page has children with no unnecessary overhead? I do not want  
to rely on a plugin for my theme to work.

Best Regards,

More information about the wp-hackers mailing list