Allowed Memory Exhausted Error after setting number of posts to 999 on WP-admin > Posts


in WP-admin > Posts (wp-admin/edit.php) I changed Paging > Number of posts on page to "999".

I got white screen:
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /wp-includes/wp-db.php on line 1889

How to fix it and prevent this error in future?


  • Adam Czajczyk

    Hello Jiri

    I hope you're well today!

    The question is: how many posts actually are there on your site? Changing this setting if there's not many posts shouldn't cause any issue.

    But if you allow up to 999 posts to be displayed on one page and there is, indeed, that many posts (or any higher number, that depends on the server performance/resources) it can indeed "eat up" available resources. It's not a bug. It is directly related to server resource usage.

    For each post that the site displays there on a list, WordPress has to fetch a number of data from the database, process it and put into memory (with some further processing to). The more posts there is (and the more complex the site is), the more database queries will be used and the more memory will be used for this.

    The error message that you're getting actually does suggest possible solution that you can try. It says that the available memory (of 256M) has been used entirely so - while this is not a bug but a natural behavior - the only way would be to either lower the number of posts being displayed on one page or to increase allowed memory limit.

    I don't know much memory is "physically available" on your server but you can try increasing it by adding following lines to the "wp-config.php" file:

    define('WP_MAX_MEMORY_LIMIT', '1024M');
    define('WP_MEMORY_LIMIT', '512M');

    You can use higher value in the 2nd line too, if you want.

    Now, this may or may not help. That depends on how much memory is really needed by your site to display all these posts and how much of it is really available on the server.

    You could check the latter by going to the "WPMU DEV -> Support" page in your site's back-end and clicking on "System info" button there. In a "PHP" tab you should see a value for "memory_limit" - that's the maximum amount of memory that can be used.

    So, if that value would be less than what you set in "wp-config.php" file and there's still an error in debug.log that gives that value as a limit, you can try increasing that to.

    Usually, in cPanel you should have some option for PHP settings (something like e.g. MultiPHP ini editor option or similar name) where you can change value of "memory_limit" for PHP - increasing that could help.

    Please note though: you can try increasing that but still there is some limit that you will not be able to overcome; some hosts doesn't allow increasing that either so in such case, decreasing the number of posts to be displayed is the only solution.

    If you have any additional questions, let me know please,

    Kind regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.