add parent arg to get_pages()
|Reported by:||DD32||Owned by:||anonymous|
At present, When using get_pages() with $child_of > 0 & $hierarchical == false, *every* post is called from the database, pages which are not a child of it are then filtered out.
This patch moves the child_of filtering to the SQL query for when heirarchial is not requested, This reduces the number of SQL results.
If hierarchical is true, Then every page is still called up as previous, this is mearly an optimization for the one specific case
Maintains 100% back compat from what i can see.
code: $pages = get_pages( array('child_of' => 14, 'hierarchical' => 0) ); before: "SELECT * FROM wp_posts WHERE (post_type = 'page' AND post_status = 'publish') ORDER BY post_title ASC" after: "SELECT * FROM wp_posts WHERE (post_type = 'page' AND post_status = 'publish') AND post_parent = 14 ORDER BY post_title ASC"
Change History (7)
- Component changed from Optimization to Template
- Summary changed from get_pages specific use case optimization to add parent arg to get_pages()
- Type changed from defect to enhancement