The reason why your page slows down is because of the function SQL_CALC_FOUND_ROWS
. This function fetches the values from all the rows returned and that slows down your website, as far as my knowledge.
If you do not have a specific use of the total number of rows, you should remove it. If you still need to know the total number of rows in wp_posts
table (with the filters above), you should better be doing SELECT COUNT(*) FROM your_table
References:
https://stackoverflow.com/questions/3453809/how-to-use-mysql-found-rows-in-php
https://dev.mysql.com/doc/refman/5.7/en/information-functions.html
How can I remove the SQL_CALC_FOUND_ROWS
function from the code above?
Thanks,
Martin
You can simply remove that function from your query. But before doing that, just check if you can find the SELECT FOUND_ROWS();
query. If yes, you have to replace that with SELECT COUNT(*) FROM your_table WHERE your_filters
SELECT wp_posts.ID
FROM wp_posts
LEFT JOIN wp_term_relationships
ON (wp_posts.ID = wp_term_relationships.object_id)
WHERE 1=1
AND ( wp_term_relationships.term_taxonomy_id IN (11) )
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'private')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 10
Hope, this helps you.
]]>