When try to open

When try to open the Smush page (Media -> Smush) site gives a 502 error


    Hello amit_chhangani,

    I hope you are doing great today. Thank you for your patience and sorry for the inconveniences that this issue may have caused and we hope to resolve it soon.

    After looking at the error and debug logs, the following entry in debug log suggests Smush is limited as to number of queries it can make:

    Cannot access property on non-object in /<DOCUMENT_ROOT>/wp-includes/class-wp-query.php on line 3857

    The developer has suggested we try the following code to decrease the limit from Smush's default 2000 to a lower number, I have chosen 1000 but you can set it lower or a little higher but below 2000, say 1500 for example.

    add_filter('wp_smush_query_limit', 'decrease_smush_query_limit', 99, 1 );
    function decrease_smush_query_limit( $limit ) {
    	$limit =  1000;
    	return $limit;

    You should add this code to your theme's 'functions.php' file or create a new file call it 'decreas-smush-query-limit.php' and include the follwoing content:

    //paste the above code here

    Save the file and upload it to your website in the folder 'wp-content/mu-plugins' so you will have the file in the location:


    This file will be executed automatically as a plugin but without the need to activate it. This should get rid of the errors regarding query limit and should in turn solve the issue at hand.

    Please do this change, run a test and let us know the results. We will be happy to know it worked but we will be more than happy to assist if you still need any further help.

    Have a nice day.