Why is wp_edit_posts_query $query['posts_per_page'] = -1
-
Situation: I have a blog with over 10k individual pages
Complication: wp-admin/edit.php?post_type=page fails to show the page list with a memory error (Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes) in /home/b2blogin/webapps/veodin_wp/wp-includes/wp-db.php on line 1557
, different story I tried to increase memory but that didn’t work and seems wrong?)
Solution? I was surprised how listing the pages would need more than 256M memory and dug into the code (I’m a WP/PHP novice).I found that changing these this line in post.php fixes the problem:
before:// Hierarchical types require special args. if ( is_post_type_hierarchical( $post_type ) && !isset($orderby) ) { $query['orderby'] = 'menu_order title'; $query['order'] = 'asc'; $query['posts_per_page'] = -1; $query['posts_per_archive_page'] = -1; }
after:
// Hierarchical types require special args. if ( is_post_type_hierarchical( $post_type ) && !isset($orderby) ) { $query['orderby'] = 'menu_order title'; $query['order'] = 'asc'; $query['posts_per_page'] = 10; $query['posts_per_archive_page'] = -1; }
Can anybody give me an idea of why $query[‘posts_per_page’] is set to -1 in the first place?
Also when I put a number there (10 or 1000), the page never stops to load, there is always the waiting indicator as if more is loaded in the background and the server shows long CPU activity in the php process.
I don’t understand the whole edit.php and post.php well enough to really undestand what’s going on, but I would appreaciate any pointer with regards to what kind of side effect I should expect from this hacked fix.
Even better: how should I fix this instead / how to investigate further why listing the pages consumes so much (too much) memory.
- The topic ‘Why is wp_edit_posts_query $query['posts_per_page'] = -1’ is closed to new replies.