• janmechtel

    (@janmechtel)


    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • sonic1243

    (@sonic1243)

    I think I have the same problem, investigating at the moment .. If I’m on a Edit Product page (edit post) then clicking on the Products tab (list posts) causes the page to stop responding. In the error log I have the same as posted above (wp-db.php on line 1557) as well as “WordPress database error MySQL server has gone away” and “Memory Exhausted” and “PHP Warning: implode”, many errors – and we only have 157 products.
    I’ve managed to access the “Screen Options” tab now and have reduced it to show only 50 product/posts per page, also less columns, and that has fixed it.
    I can only assume the problems came with the recent WP updates but I don’t know. And I can’t find that ‘special args’ code snippet you posted above anywhere in my files?!

    Thread Starter janmechtel

    (@janmechtel)

    I’m still struggling with this.

    Now it appears that the “Page Attributes” section on the single page edit like: /wp-admin/post.php?post=4&action=edit never finishes loading either.

    @sonic1243 the post.php is located in /wp-admin/includes/post.php would be interesting to know if that helps in your case as well.

    GumbyDammit

    (@gumbydammit)

    I am having this exact same problem. If I rename my plugins folder, then I can get the page to load. Then I’m able to access screen options and change the number of posts per page. After that, I rename the plugins folder back and violoa, I’m able to see my lists of posts again.

    The trouble with this method is that it only helps me, not my other users (unless I had everyone go in and do this at the same time.) What I’m now looking for is a way to decrease the default number of posts per page.

    I am assuming that there must be something going on with a particular post that is causing it to return a huge result set causing the memory error. But I’m just a novice so I may have no clue what I’m talking about. (very likely actually.)

    Thread Starter janmechtel

    (@janmechtel)

    @GumbyDmmit renaming the plugins folder makes no difference for me ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Why is wp_edit_posts_query $query['posts_per_page'] = -1’ is closed to new replies.