wp_list_pages can cause huge numbers of SQL queries
|Reported by:||Otto42||Owned by:|
|Milestone:||Priority:||highest omg bbq|
Summary: wp_list_pages makes use of the Walker_Page class. Walker_Page calls get_page() which calls get_post() which calls _get_post_ancestors() which is not cached.
On a large set of pages, the _get_post_ancestors() function being called this often can result in a huge amount of queries to the database, all taking this form:
SELECT post_parent FROM wp_posts WHERE ID= 'page_id' LIMIT 1
When you have nested pages in a large hierarchy, this rapidly grows obscene in terms of the number of queries performed, since it must execute one query to track each page back to the root of the hierarchy.
Doing a wp_list_pages on the above set of pages results in 12 separate queries to the database, just to get post_parents. Adding just one more subpage, like /pageroot/1/2/5/ will add 4 more queries.
Problems reported in the support forum have gotten up to 2000+ queries from one call to wp_list_pages.